+ Changed from MySQL to MySQLi native driver.
+ Added 2 new functions in DataBase class: fetch($query) and num_rows($query) git-svn-id: https://svn.pioder.pl/uf-svn/uF@20 72ec579a-5ced-4fa4-82f3-afba5d98df2f
This commit is contained in:
@@ -11,16 +11,35 @@ if ( !defined('IN_uF') )
|
||||
{
|
||||
die('Hacking attempt');
|
||||
}
|
||||
|
||||
$db;
|
||||
|
||||
class DataBase
|
||||
{
|
||||
function db_connect()
|
||||
{
|
||||
$connect = mysql_pconnect(DB_HOST, DB_USER, DB_PASS) or message_die('CRITICAL',' Could not connect to database server.',mysql_error());
|
||||
mysql_query("SET NAMES 'utf8'",$connect);
|
||||
mysql_select_db(DB_NAME, $connect) or message_die('CRITICAL',' Could not connect to database.',mysql_error());
|
||||
global $db;
|
||||
|
||||
$db = new mysqli(DB_HOST, DB_USER, DB_PASS);
|
||||
if (mysqli_connect_errno() != 0)
|
||||
{
|
||||
message_die('CRITICAL',' Could not connect to database server.',$db->error);
|
||||
}
|
||||
|
||||
if (!$db->set_charset("UTF8"))
|
||||
{
|
||||
message_die('CRITICAL', 'Could not set character set UTF-8', $db->error);
|
||||
}
|
||||
if (!$db->select_db(DB_NAME))
|
||||
{
|
||||
message_die('CRITICAL',' Could not select database.', $db->error);
|
||||
}
|
||||
}
|
||||
|
||||
function sql_query($sql, $type, $msg, $no_count = false)
|
||||
{
|
||||
global $db;
|
||||
|
||||
if (isset($_COOKIE['queries']))
|
||||
{
|
||||
$no_count = false;
|
||||
@@ -30,11 +49,28 @@ class DataBase
|
||||
}
|
||||
}
|
||||
//echo '<span class="fsmall">'.$sql.'<br></span>'; //for optimizing only
|
||||
$query = mysql_query($sql) or message_die($type, $msg, mysql_error());
|
||||
if (!$query = $db->query($sql))
|
||||
{
|
||||
message_die($type, $msg, $db->error);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
function fetch($query)
|
||||
{
|
||||
return $query->fetch_array();
|
||||
}
|
||||
|
||||
function num_rows($query)
|
||||
{
|
||||
return $query->num_rows;
|
||||
}
|
||||
|
||||
function new_id($table)
|
||||
{
|
||||
global $db;
|
||||
|
||||
//check table id
|
||||
switch($table)
|
||||
{
|
||||
@@ -55,7 +91,7 @@ class DataBase
|
||||
case WARNINGS_TABLE: { $id = 'w_id'; break; }
|
||||
}
|
||||
$sql = "SELECT `$id` FROM $table ORDER BY `$id` DESC LIMIT 1";
|
||||
$return_id = mysql_fetch_array(DataBase::sql_query($sql,'GENERAL','Error with obtain last id.<br> File: db.php, Line: '.__LINE__));
|
||||
$return_id = DataBase::fetch(DataBase::sql_query($sql,'GENERAL','Error with obtain last id.<br> File: db.php, Line: '.__LINE__));
|
||||
$return_id = $return_id[$id];
|
||||
$return_id = $return_id+1;
|
||||
return $return_id;
|
||||
|
||||
Reference in New Issue
Block a user