Commit 12512a6f authored by Loïc DAYOT's avatar Loïc DAYOT Committed by Ploc
Browse files

chore: code adaptation to mysqli

Due to warnings in recent php version, migrate from mysql to mysqli extension.
parent 44ace62f
......@@ -30,34 +30,32 @@
class db
{
function db()
var $db_link;
function __construct()
{
global $db_host;
global $db_user;
global $db_pass;
global $db_name;
if(@mysql_connect($db_host,$db_user,$db_pass)==FALSE)
$this->db_link = @new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($this->db_link->connect_errno)
{
echo "Probleme de connexion à la base de données sur $db_host.\n";
return 0;
echo "Erreur de connexion (".
$this->db_link->connect_errno . ") ". $this->db_link->connect_error;
die();
}
if(@mysql_select_db($db_name) == FALSE)
{
echo "Problème de selection de la base de données $db_name sur $db_host.\n";
return 0;
}
mysql_query("set names 'utf8'");
$this->query("set names 'utf8'");
}
function query ($query)
{
if( ($result = @mysql_query($query)) == FALSE)
if( ($result = $this->db_link->query($query)) == FALSE)
{
echo "Probleme dans la syntaxe de $query : " . mysql_error() . "\n";
return 0;
echo "Probleme dans la syntaxe de $query : " . $this->db_link->error . "\n";
return 0;
}
return $result;
......@@ -65,37 +63,37 @@ class db
function insertid ()
{
return mysql_insert_id ();
return $this->db_link->insert_id;
}
function fetchObject ($result)
{
return mysql_fetch_object($result);
return $result->fetch_object();
}
function fetchArray ($result)
{
return mysql_fetch_array($result);
return $result->fetch_array();
}
function fetchRow ($result)
{
return mysql_fetch_row($result);
return $result->fetch_row();
}
function freeResult ($result)
{
return mysql_free_result($result);
return $result->free_result();
}
function numRows ($result)
{
return mysql_num_rows($result);
return $result->num_rows;
}
function getOne($result) {
$row = $this->fetchArray($result);
return $row[0];
$row = $this->fetchArray($result);
return $row[0];
}
/**
......@@ -111,7 +109,7 @@ class db
$value = stripslashes($value);
if (!is_numeric($value))
$value = "'" . mysql_real_escape_string($value) . "'";
$value = "'" . $this->db_link->real_escape_string($value) . "'";
return $value;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment