108 lines
3.1 KiB
PHP
108 lines
3.1 KiB
PHP
<?php
|
|
//--------------------------------------------------------------------//
|
|
// Filename : class/database/mysql.php //
|
|
// Software : XOCP - X Open Community Portal //
|
|
// Version : 0.1 //
|
|
// Date : 2002-11-09 //
|
|
// Author : adiet //
|
|
// License : GPL //
|
|
//--------------------------------------------------------------------//
|
|
|
|
if ( !defined('MYSQL_DATABASE_DEFINED') ) {
|
|
define('MYSQL_DATABASE_DEFINED', TRUE);
|
|
|
|
class Database extends mysqli {
|
|
var $debug = TRUE;
|
|
|
|
public function __construct($dbhost=NULL,$dbuser=NULL,$dbpass=NULL,$dbname=NULL,$dbport=NULL) {
|
|
if(!isset($dbname)) {
|
|
parent::__construct(_XOCP_DB_HOST,_XOCP_DB_USER,_XOCP_DB_PASS,_XOCP_DB_NAME,_XOCP_DB_PORT);
|
|
} else {
|
|
parent::__construct($dbhost,$dbuser,$dbpass,$dbname,$dbport);
|
|
}
|
|
|
|
if (mysqli_connect_error()) {
|
|
die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
|
|
}
|
|
}
|
|
|
|
public static function getInstance($dbhost=NULL,$dbuser=NULL,$dbpass=NULL,$dbname=NULL,$dbport=NULL) {
|
|
if(!isset($dbname)) {
|
|
return new Database(_XOCP_DB_HOST,_XOCP_DB_USER,_XOCP_DB_PASS,_XOCP_DB_NAME,_XOCP_DB_PORT);
|
|
} else {
|
|
return new Database($dbhost,$dbuser,$dbpass,$dbname,$dbport);
|
|
}
|
|
}
|
|
|
|
function getRowsNum(&$result) {
|
|
if(is_object($result)) return $result->num_rows;
|
|
return FALSE;
|
|
}
|
|
|
|
function getInsertId() {
|
|
return $this->insert_id;
|
|
}
|
|
|
|
function fetchRow(&$result) {
|
|
if(is_object($result)) return $result->fetch_row();
|
|
return FALSE;
|
|
}
|
|
|
|
function fetchArray(&$result) {
|
|
if(is_object($result)) return $result->fetch_array(MYSQLI_ASSOC);
|
|
return FALSE;
|
|
}
|
|
|
|
function fetchObject(&$result) {
|
|
if(is_object($result)) return $result->fetch_object();
|
|
return FALSE;
|
|
}
|
|
|
|
function fieldName(&$result,$i) {
|
|
if(is_object($result)) return $result->fetch_field($i);
|
|
return FALSE;
|
|
}
|
|
|
|
function fetchField(&$result,$i) {
|
|
if(is_object($result)) return $result->fetch_field_direct($i);
|
|
return FALSE;
|
|
}
|
|
|
|
function getFieldsNum(&$result) {
|
|
if(is_object($result)) return $result->field_count;
|
|
return FALSE;
|
|
}
|
|
|
|
function getAffectedRows() {
|
|
if(is_object($result)) return $this->affected_rows;
|
|
return FALSE;
|
|
}
|
|
|
|
function freeRecordSet(&$result) {
|
|
if(is_object($result)) return $result->free();
|
|
}
|
|
|
|
function error() {
|
|
return $this->error;
|
|
}
|
|
|
|
function errno() {
|
|
return $this->errno;
|
|
}
|
|
|
|
function &query($sql) {
|
|
$result = parent::query($sql);
|
|
if($this->errno!=0) {
|
|
if ( $this->debug ) {
|
|
$errorMsg = @$this->error;
|
|
$errorNum = @$this->errno;
|
|
_debuglog("MySQL Query Error: $sql\nError Number: $errorNum\nError Message: $errorMsg");
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
|
|
} // MYSQL_DATABASE_DEFINED
|