summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominique Martinet <asmadeus@codewreck.org>2020-05-08 11:02:16 +0000
committerDominique Martinet <asmadeus@codewreck.org>2020-05-08 11:02:16 +0000
commit773681a3ba14cde8b00b910356b3a71f2f8a1a13 (patch)
tree0d2a843bb6f8606e444160daa137b490f0112039
parentc03e092468136010d27115263c6e6857aae1f86a (diff)
php7 compat: use mysqli for mysql dbal
-rw-r--r--dbal/mysql.php69
1 files changed, 16 insertions, 53 deletions
diff --git a/dbal/mysql.php b/dbal/mysql.php
index 0d1d508..3dc860f 100644
--- a/dbal/mysql.php
+++ b/dbal/mysql.php
@@ -42,47 +42,19 @@ class SQL_DB
* @param $dbname Database name
* @param $dbuser Database username
* @param $dbpass Database password
- * @param $pconnect Use persistent connection
* @return mixed Link ID / false
*/
- function sql_db($dbhost, $dbname, $dbuser, $dbpass='', $pconnect = false)
+ function sql_db($dbhost, $dbname, $dbuser, $dbpass='')
{
- $this->pconnect = $pconnect;
$this->dbhost = $dbhost;
$this->dbname = $dbname;
$this->dbuser = $dbuser;
$this->dbpass = $dbpass;
- if ( $this->pconnect )
- {
- if ( empty($this->dbpass) )
- {
- $this->link_id = @mysql_pconnect($this->dbhost, $this->dbuser);
- }
- else
- {
- $this->link_id = @mysql_pconnect($this->dbhost, $this->dbuser, $this->dbpass);
- }
- }
- else
- {
- if ( empty($this->dbpass) )
- {
- $this->link_id = @mysql_connect($this->dbhost, $this->dbuser);
- }
- else
- {
- $this->link_id = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpass);
- }
- }
+ $this->link_id = @mysqli_connect($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
- if ( (is_resource($this->link_id)) && (!is_null($this->link_id)) && ($this->dbname != '') )
+ if ( !$this->link_id->connect_errno )
{
- if ( !@mysql_select_db($this->dbname, $this->link_id) )
- {
- @mysql_close($this->link_id);
- $this->link_id = false;
- }
return $this->link_id;
}
else
@@ -102,9 +74,9 @@ class SQL_DB
{
if ( $this->query_id )
{
- @mysql_free_result($this->query_id);
+ @mysqli_free_result($this->query_id);
}
- return @mysql_close($this->link_id);
+ return @mysqli_close($this->link_id);
}
else
{
@@ -119,8 +91,8 @@ class SQL_DB
*/
function error()
{
- $result['message'] = @mysql_error();
- $result['code'] = @mysql_errno();
+ $result['message'] = @mysqli_error();
+ $result['code'] = @mysqli_errno();
return $result;
}
@@ -141,17 +113,14 @@ class SQL_DB
if ( $query != '' )
{
$this->query_count++;
- $this->query_id = @mysql_query($query, $this->link_id);
+ $this->query_id = @mysqli_query($this->link_id, $query);
}
- if ( !empty($this->query_id) )
+ if ( $this->query_id )
{
if ( DEBUG == 2 )
{
$this->queries[$this->query_count] = $query;
}
-
- unset($this->record[$this->query_id]);
- unset($this->record_set[$this->query_id]);
return $this->query_id;
}
else
@@ -268,8 +237,7 @@ class SQL_DB
if ( $query_id )
{
- $this->record[$query_id] = @mysql_fetch_array($query_id);
- return $this->record[$query_id];
+ return @mysqli_fetch_array($query_id);
}
else
{
@@ -291,11 +259,9 @@ class SQL_DB
}
if ( $query_id )
{
- unset($this->record_set[$query_id]);
- unset($this->record[$query_id]);
- while ( $this->record_set[$query_id] = @mysql_fetch_array($query_id) )
+ while ( $record_set = @mysqli_fetch_array($query_id) )
{
- $result[] = $this->record_set[$query_id];
+ $result[] = $record_set;
}
return $result;
}
@@ -320,7 +286,7 @@ class SQL_DB
if ( $query_id )
{
- $result = @mysql_num_rows($query_id);
+ $result = @mysqli_num_rows($query_id);
return $result;
}
else
@@ -336,7 +302,7 @@ class SQL_DB
*/
function affected_rows()
{
- return ( $this->link_id ) ? @mysql_affected_rows($this->link_id) : false;
+ return ( $this->link_id ) ? @mysqli_affected_rows($this->link_id) : false;
}
/**
@@ -348,7 +314,7 @@ class SQL_DB
{
if ( $this->link_id )
{
- $result = @mysql_insert_id($this->link_id);
+ $result = @mysqli_insert_id($this->link_id);
return $result;
}
else
@@ -372,10 +338,7 @@ class SQL_DB
if ( $query_id )
{
- unset($this->record[$query_id]);
- unset($this->record_set[$query_id]);
-
- @mysql_free_result($query_id);
+ @mysqli_free_result($query_id);
return true;
}