note 102741 added to mysqli-stmt.bind-param

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
I borrowed the code from canche_x at yahoo dot com and modified a bit to create an abstract class to be inherited, to handle easily the use of prepared statements, and even to auto alias it to a string name.

I hope someone gets this usefull as I did many times :)

Example of usage:
<?php

require_once 'MySQLDatabase.php';

class MyDatabase extends MySQLDatabase {
	private function PrepareAllStatements() {
		$this->PrepareSTMT("test1", "SELECT COUNT(id) AS countid FROM users");
		$this->PrepareSTMT("test2", "UPDATE users SET pass_hash=? WHERE id=?");
		// ...
	}

	public function __construct() {
		parent::__construct();
		$this->Connect("localhost", "foo", "bar", "mywebdb");
		$this->PrepareAllStatements();
	}

	public function __destruct() {
		parent::__destruct();
	}

	public function GetTotalUsers() {
		$result=0;
		$tmp=$this->ExecuteQuery("test1");
		if (isset($tmp[0]['countid']) {
			$result=$tmp[0]['countid'];
		}
		return $result;
	}

	public function UpdatePass($userid, $hash) {
		$affected_rows=$this->ExecuteQuery("test2", $userid, $hash);
		return ($affected_rows==1);
	}
	//...
};

//To use it is simple! Example of usage:
$db=new MyDatabase();
echo "I have ".$db->GetTotalUsers()." users now.<br />";
if ($db->UpdatePass(1, "somehash")) {
	echo "Password succesfully updated for user #1";
}
else {
	echo "Update failed!<br />";
}

?>

The code itself is a bit large, but it is published in my blog: http://www.stormbyte.blogspot.com as well as in pastebin: http://pastebin.com/ccZqgT5M
----
Server IP: 69.147.83.197
Probable Submitter: 80.239.242.159 (proxied: 84.120.230.154)
----
Manual Page -- http://www.php.net/manual/en/mysqli-stmt.bind-param.php
Edit        -- https://master.php.net/note/edit/102741
Del: integrated  -- https://master.php.net/note/delete/102741/integrated
Del: useless     -- https://master.php.net/note/delete/102741/useless
Del: bad code    -- https://master.php.net/note/delete/102741/bad+code
Del: spam        -- https://master.php.net/note/delete/102741/spam
Del: non-english -- https://master.php.net/note/delete/102741/non-english
Del: in docs     -- https://master.php.net/note/delete/102741/in+docs
Del: other reasons-- https://master.php.net/note/delete/102741
Reject      -- https://master.php.net/note/reject/102741
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.