<?php
/**
* Quicksilver Forums
* Copyright (c) 2005-2011 The Quicksilver Forums Development Team
* http://code.google.com/p/quicksilverforums/
*
* Based on MercuryBoard
* Copyright (c) 2001-2005 The Mercury Development Team
* http://www.mercuryboard.com/
*
* 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.
*
**/
if (!defined('QUICKSILVERFORUMS')) {
header('HTTP/1.0 403 Forbidden');
die;
}
require_once $set['include_path'] . '/lib/database.php';
/**
* MySQLi Abstraction Class
*
* @author Jason Warner <hide@address.com>
* @author Roger Libiez [Samson] http://www.iguanadons.net
* @since 1.5
**/
class db_mysqli extends database
{
var $socket; // Database Socket @var string
/**
* Constructor; sets up variables and connection
*
* @param string $db_host Server
* @param string $db_user User Name
* @param string $db_pass Password
* @param string $db_name Database Name
* @param int $db_port Database Port
* @param string $db_socket Database Socket
* @param string $db_prefix Prefix applied to all database queries
* @author Jason Warner <hide@address.com>
* @since Beta 2.0
* @return void
**/
function db_mysqli($db_host, $db_user, $db_pass, $db_name, $db_port = 3306, $db_socket = '', $db_prefix)
{
parent::database($db_host, $db_user, $db_pass, $db_name, $db_port, $db_socket, $db_prefix);
$this->socket = $db_socket;
$this->connection = new mysqli( $db_host, $db_user, $db_pass, $db_name /* , $db_port, $db_socket */ );
if (!$this->connection->select_db( $db_name )) {
$this->connection = false;
}
}
function close()
{
if( $this->connection )
$this->connection->close();
}
/**
* Runs an EXPLAIN or similar on a query
*
* @param string $query Query to debug
* @access protected
* @author Jason Warner <hide@address.com>
* @since Beta 2.0
* @return void
**/
function get_debug_info($query)
{
$data = array();
if (substr(trim(strtoupper($query)), 0, 6) == 'SELECT') {
$result = $this->connection->query("EXPLAIN $query") or error(QUICKSILVER_QUERY_ERROR, $this->connection->error, $query, $this->connection->errno);
$data = $result->fetch_array(MYSQLI_ASSOC);
}
return $data;
}
/**
* Retrieves the insert ID of the last executed query
*
* @param string $table Table name - unused
* @author Jason Warner <hide@address.com>
* @since Beta 2.1
* @return int Insert ID
**/
function insert_id($table)
{
return $this->connection->insert_id;
}
/**
* Executes a query
*
* @param string $query SQL query
* @param string $args Data to pass into query as escaped strings
* @author Jason Warner <hide@address.com>
* @since Beta 2.0
* @return resource Executed query
**/
function query($query)
{
$args = array();
if (is_array($query)) {
$args = $query; // only use arg 1
} else {
$args = func_get_args();
}
$query = $this->_format_query($args);
$this->querycount++;
if (isset($this->get['debug'])) {
$this->debug($query);
}
$result = $this->connection->query($query) or error(QUICKSILVER_QUERY_ERROR, $this->connection->error, $query, $this->connection->errno);
return $result;
}
/**
* Fetches an executed query into an array
*
* @param resource $query Executed SQL query
* @author Jason Warner <hide@address.com>
* @since Beta 2.0
* @return array Fetched rows
**/
function nqfetch($query)
{
return $query->fetch_array(MYSQLI_ASSOC);
}
function nqfetch_row($query)
{
return $query->fetch_row();
}
/**
* Gets the number of rows retrieved by a SELECT
*
* @param resource $query Executed SQL query
* @author Jason Warner <hide@address.com>
* @since Beta 2.0
* @return int Number of retrieved rows
**/
function num_rows($query)
{
return $query->num_rows;
}
/**
* Gets the number of rows affected by the last executed UPDATE
*
* @author Jason Warner <hide@address.com>
* @since Beta 2.1
* @return int Number of affected rows
**/
function aff_rows()
{
return $this->connection->affected_rows;
}
/**
* Returns a escaped string
*
* @author Matthew Lawrence <hide@address.com>
* @since 1.3.0
* @return string A string with the quotes and other charaters escaped
* @param string $string The string to escape
**/
function escape($string)
{
return $this->connection->real_escape_string($string);
}
function invalid($errmsg)
{
if (stristr($errmsg, 'mysqli_fetch_array(): supplied argument is not a valid MySQLi result resource'))
return true;
return false;
}
function error_last()
{
return $this->connection->error;
}
}
?>