mysqli_stmt_bind_result

From: Date: Wed, 19 Mar 2008 01:25:25 +0000
Subject: mysqli_stmt_bind_result
Groups: php.general 
Request: Send a blank email to php-general+get-271756@lists.php.net to get a copy of this message
If I use mysqli's prepared statements in an object and call mysqli_stmt_bind_params, into which scope does mysqli_stmt_fetch() place the variables? Can I control it? As of yet, I have no idea where fetch() stores the results. It is fetching valid data. I'd really like to use the OO style of MySQLi if possible. Any help or guidance is greatly appreciated. The offending code is as follows: class StmtIterator { private $data = 'test'; private $host = 'localhost'; private $user = 'root'; private $pass = ''; private $db; // Database connection private $st; // Prepared statement private $sql = ""; public function __construct ($sql, Array $params){ $this->db = mysqli_init(); $this->db->real_connect($this->host, $this->user, $this->pass, $this-
data);
$this->sql = $sql; $this->st = $this->db->stmt_init(); $this->st->prepare($this->sql); $this->st->execute(); call_user_func_array(array($this->st, 'bind_result'), $params); } public function fetch (){ $result = $this->st->fetch(); if ($result !== true) echo "No data fetched."; echo "Name is...<br /> "; echo isset($this->st->name) ? "in this->st->name as {$this->st->name}.<br />" : null; echo isset($this->db->name) ? "in this->db->name as {$this->db->name}.<br />" : null; echo isset($this->params['name']) ? "in this->params['name'] as {$this->params['name']}.<br />" : null; echo isset($this->name) ? " this->name as {$this->name}.<br />" : null; echo isset($name) ? "in name as {$name}.<br />" : null; return $result; } public function __destruct (){ $this->st->close(); $this->db->close(); } } $sql = " SELECT id, name FROM user WHERE 1 "; $params = array( 'id', 'name', ); $user_iterator = new StmtIterator($sql, $params); while ($user_iterator->fetch()){ echo isset($this->db->name) ? "in the local scope name as {$name}.<br />" : null; } Jeremy Mcentire Ant Farmer ZooToo LLC

« previous php.general (#271756) next »