Source for file DB_MySQLi.class.php
Documentation is available at DB_MySQLi.class.php
// Copyright 2006 Jan Pieter Kunst <jpkunst at xs4all dot nl>
// Based on Personal Weblog 1.0.0
// http://www.kyne.com.au/~mark/software/weblog.php
// Copyright 2001,2002 Mark Pulford <mark@kyne.com.au>
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Class to make a connection to a MySQL database with the mysqli extension
* @var obj database connection object
* @var string name of the weblog database
* @param string name of weblog database
* @param string host of weblog database
* @param string username for weblog database
* @param string password for weblog database
public function __construct($db, $host, $user, $pass) {
trigger_error('You need the "mysqli" extension to run this program', E_USER_ERROR);
// Ensure the database exists
* Method to perform queries to SELECT from the database
* @param string SQL query with placeholders if needed
* @param array array with values for placeholders
* @return array numeric array of found associative rows from the database
public function fetch($sql, $params =
array()) {
// Must ensure correct DB is selected. If some other PHP
// code has run it might have changed the db in between
// Weblog() and insert().
foreach($fieldinfo as $val) {
// See http://www.php.net/manual/en/function.mysqli-stmt-bind-result.php
// generate variables for storing result
$vars[] =
& $row[$val->name];
// reference to statement must be first parameter of call to mysqli_stmt_bind_result
// $array[] = $row seems to assign a reference instead of a copy
foreach($row as $k =>
$v) {
* Method to perform queries that change the database (INSERT, UPDATE, DELETE)
* @param string SQL query with placeholders
* @param array array with values for placeholders
* @return int number of affected rows
public function change($sql, $params) {
* Private method to prepare and execute a mysqli prepared statement
* @param string SQL query with placeholders
* @param array array with values for placeholders
* @return obj mysqli_stmt object
foreach($params as $key =>
$param) {
// string of types must be second parameter of call to mysqli_stmt_bind_param
// reference to statement must be first parameter of call to mysqli_stmt_bind_param
* Method to test if connection to database is established
* @return bool FALSE if not connected, TRUE otherwise
Documentation generated on Sun, 17 Jun 2007 19:20:35 +0200 by phpDocumentor 1.3.2