lcerbaro Posted September 25, 2011 Report Share Posted September 25, 2011 (edited) Olá, estou criando uma classe de conexão usando a extensão MySQLi, porém estou com bastante dificuldades de concluir.Gostaria da ajuda e experiência de vocês, obrigado.<?php /* /Classes/SQLi.php */ class Sql extends MySQLi { private $host, $user, $pass, $database; protected $db = null; public $id; public function __construct($host, $user, $pass, $database) { $this->host = $host; $this->user = $user; $this->pass = $pass; $this->database = $database; //parent::__construct($host,$user,$pass,$database); //$this->init(); //$this->real_connect(); $this->getInstance(); } public function getInstance() { if ($this->db === null) { parent::__construct($this->host,$this->user,$this->pass,$this->database); } return $this; } public function query($query) { $db = $this->getInstance(); //$query = $db->real_escape_string($query); $result = $db->real_query($query); //$res = $this->store_result(); $this->id = $this->insert_id; return new SqlR($db); } } class SqlR extends MySQLi_Result { protected $db = null; public function __construct($db) { $this->db = $db; $this->getInstance(); } public function getInstance() { if($this->db === null) { parent::__construct(); } return $this; } public function fetch() { $db = $this->getInstance(); return $db->fetch_object(); } public function rows() { $db = $this->getInstance(); return $db->num_rows; } public function rewind() { $db = $this->getInstance(); return $db->data_seek(0); } public function seek($i) { $db = $this->getInstance(); return $db->data_seek($i); } } ?> Aqui um exemplo de uso: <?php /* /page/index.php */ ini_set('display_errors', true); error_reporting(-1); require_once "../Classes/SQLi.php"; $db = new Sql("localhost","root","","mydb"); $sql= "select * from tablename"; $res = $db->query($sql); while($rows = $res->fetch()) var_dump($rows); ?>E o erro:( ! ) Fatal error: Call to undefined method mysqli_result::fetch() in C:\wamp\www\newtry\index.php on line 12 Edited September 26, 2011 by lcerbaro Quote Link to comment Share on other sites More sharing options...
Question
lcerbaro
Olá, estou criando uma classe de conexão usando a extensão MySQLi, porém estou com bastante dificuldades de concluir.
Gostaria da ajuda e experiência de vocês, obrigado.
Aqui um exemplo de uso:E o erro:
Edited by lcerbaroLink to comment
Share on other sites
0 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.