mysqli_stmt_bind_result

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux