<?php
/**********************************************
* @app:
* @file: ./lib/sal.php
* @modified: September 21, 2006
* @modifier: dStreSd
* @function: mysql4 DBAL
**********************************************/
// Note: This is an older version of the mysql4 api file
define('SF_BOTH', 1);
define('SF_NUM', 2);
define('SF_ASSOC', 3);
class SALResource {
var $num_rows;
var $affected_rows;
var $insert_id;
var $resource;
var $select;
function SALResource($query, &$dblink) {
$this->select = (substr($query, 0, 6) == 'SELECT') ? true : false;
$this->resource = mysql_query($query, $dblink);
if(!$this->resource) {
echo 'The query was malformed or incorrect, please report this issue to the administrator.<br>';
echo '<b>Query:</b> ' . $query . '';
exit;
} else {
if($this->select) {
$this->num_rows = mysql_num_rows($this->resource);
} else {
$this->affected_rows = mysql_affected_rows();
if(substr($query, 0, 6) == 'INSERT') {
$this->insert_id = mysql_insert_id();
}
}
}
}
function fetch_array($assoc_or_num = SF_BOTH) {
switch($assoc_or_num) {
case SF_BOTH :
case MF_BOTH : // Insures mysqli compatibility
default :
return mysql_fetch_array($this->resource);
break;
case SF_NUM :
case MF_NUM : // Insures mysqli compatibility
return mysql_fetch_row($this->resource);
break;
case SF_ASSOC :
case MF_ASSOC : // Insures mysqli compatibility
return mysql_fetch_assoc($this->resource);
break;
}
}
function fetch_row() {
return $this->fetch_array(SF_NUM);
}
function fetch_assoc() {
return $this->fetch_array(SF_ASSOC);
}
function close() {
@ mysql_free_result($this->resource);
unset($this->resource);
}
}
class SAL {
var $dblink;
var $queries;
var $curQueryID;
var $queryCount;
function SAL($host, $user, $pass, $database, $port = null, $socket = null, $persistant = true) {
$this->curQueryID = 0;
$this->queries = array();
if($persistant) {
@ $connected = mysql_pconnect($host, $user, $pass);
} else {
@ $connected = mysql_connect($host, $user, $pass);
}
if(!$connected) {
echo 'Connection to the mysql server wasn\'t possible; most likely the username, password, or host name was incorrect.';
exit;
} else {
@ $db = mysql_select_db($database);
if(!$db) {
echo 'The database couldn\'t be selected, report this issue to the administrator.';
exit;
} else {
$this->dblink = $connected;
return true;
}
}
}
function query($query) {
if(defined('STORE_QUERIES') && STORE_QUERIES == true) {
$this->queries[$this->curQueryID++] = $query;
$this->queryCount = $this->curQueryID;
}
return new SALResource($query, $this->dblink);
}
}
?>