|
Line 0
Link Here
|
|
|
1 |
--- include/db/mysql.php.orig 2016-04-08 09:50:59 UTC |
| 2 |
+++ include/db/mysql.php |
| 3 |
@@ -29,13 +29,13 @@ function mysql_connect_db($host = null, |
| 4 |
$port = $config["dbport"]; |
| 5 |
|
| 6 |
// Non-persistent connection: This will help to avoid mysql errors like "has gone away" or locking problems |
| 7 |
- // If you want persistent connections change it to mysql_pconnect(). |
| 8 |
- $connect_id = @mysql_connect($host . ":" . $port, $user, $pass, true); |
| 9 |
+ // If you want persistent connections change it to mysqli_pconnect(). |
| 10 |
+ $connect_id = @mysqli_connect($host . ":" . $port, $user, $pass); |
| 11 |
if (! $connect_id) { |
| 12 |
return false; |
| 13 |
} |
| 14 |
|
| 15 |
- mysql_select_db($db, $connect_id); |
| 16 |
+ mysqli_select_db($connect_id, $db); |
| 17 |
return $connect_id; |
| 18 |
} |
| 19 |
|
| 20 |
@@ -299,14 +299,14 @@ function mysql_db_process_sql($sql, $ret |
| 21 |
$dbconnection = $config['dbconnection']; |
| 22 |
} |
| 23 |
|
| 24 |
- $result = mysql_query ($sql, $dbconnection); |
| 25 |
+ $result = mysqli_query($dbconnection, $sql); |
| 26 |
|
| 27 |
$time = microtime (true) - $start; |
| 28 |
if ($result === false) { |
| 29 |
$backtrace = debug_backtrace (); |
| 30 |
$error = sprintf ('%s (\'%s\') in <strong>%s</strong> on line %d', |
| 31 |
- mysql_error (), $sql, $backtrace[0]['file'], $backtrace[0]['line']); |
| 32 |
- db_add_database_debug_trace ($sql, mysql_error ($dbconnection)); |
| 33 |
+ mysqli_error($dbconnection), $sql, $backtrace[0]['file'], $backtrace[0]['line']); |
| 34 |
+ db_add_database_debug_trace ($sql, mysqli_error($dbconnection)); |
| 35 |
set_error_handler ('db_sql_error_handler'); |
| 36 |
trigger_error ($error); |
| 37 |
restore_error_handler (); |
| 38 |
@@ -314,29 +314,29 @@ function mysql_db_process_sql($sql, $ret |
| 39 |
} |
| 40 |
elseif ($result === true) { |
| 41 |
if ($rettype == "insert_id") { |
| 42 |
- $result = mysql_insert_id ($dbconnection); |
| 43 |
+ $result = ((is_null($___mysqli_res = mysqli_insert_id($dbconnection))) ? false : $___mysqli_res); |
| 44 |
} |
| 45 |
elseif ($rettype == "info") { |
| 46 |
- $result = mysql_info ($dbconnection); |
| 47 |
+ $result = mysqli_info($dbconnection); |
| 48 |
} |
| 49 |
else { |
| 50 |
- $result = mysql_affected_rows ($dbconnection); |
| 51 |
+ $result = mysqli_affected_rows($dbconnection); |
| 52 |
} |
| 53 |
|
| 54 |
- db_add_database_debug_trace ($sql, $result, mysql_affected_rows ($dbconnection), |
| 55 |
+ db_add_database_debug_trace ($sql, $result, mysqli_affected_rows($dbconnection), |
| 56 |
array ('time' => $time)); |
| 57 |
return $result; |
| 58 |
} |
| 59 |
else { |
| 60 |
- db_add_database_debug_trace ($sql, 0, mysql_affected_rows ($dbconnection), |
| 61 |
+ db_add_database_debug_trace ($sql, 0, mysqli_affected_rows($dbconnection), |
| 62 |
array ('time' => $time)); |
| 63 |
- while ($row = mysql_fetch_assoc ($result)) { |
| 64 |
+ while ($row = mysqli_fetch_assoc($result)) { |
| 65 |
array_push ($retval, $row); |
| 66 |
} |
| 67 |
|
| 68 |
if ($cache === true) |
| 69 |
$sql_cache[$sql] = $retval; |
| 70 |
- mysql_free_result ($result); |
| 71 |
+ ((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
@@ -355,7 +355,8 @@ function mysql_db_process_sql($sql, $ret |
| 76 |
* @return string String cleaned. |
| 77 |
*/ |
| 78 |
function mysql_escape_string_sql($string) { |
| 79 |
- $str = mysql_real_escape_string($string); |
| 80 |
+ global $config; |
| 81 |
+ $str = mysqli_real_escape_string($config['dbconnection'], $string); |
| 82 |
|
| 83 |
return $str; |
| 84 |
} |
| 85 |
@@ -754,10 +755,10 @@ function mysql_db_get_all_rows_filter ($ |
| 86 |
function mysql_db_get_num_rows ($sql) { |
| 87 |
global $config; |
| 88 |
|
| 89 |
- $result = mysql_query($sql, $config['dbconnection']); |
| 90 |
+ $result = mysqli_query($config['dbconnection'], $sql); |
| 91 |
|
| 92 |
if ($result) { |
| 93 |
- return mysql_num_rows($result); |
| 94 |
+ return mysqli_num_rows($result); |
| 95 |
} |
| 96 |
else { |
| 97 |
return 0; |
| 98 |
@@ -972,11 +973,12 @@ function mysql_db_process_sql_delete($ta |
| 99 |
* @return mixed The row or false in error. |
| 100 |
*/ |
| 101 |
function mysql_db_get_all_row_by_steps_sql($new = true, &$result, $sql = null) { |
| 102 |
+ global $config; |
| 103 |
if ($new == true) |
| 104 |
- $result = mysql_query($sql); |
| 105 |
+ $result = mysqli_query($config['dbconnection'], $sql); |
| 106 |
|
| 107 |
if ($result) { |
| 108 |
- return mysql_fetch_assoc($result); |
| 109 |
+ return mysqli_fetch_assoc($result); |
| 110 |
} |
| 111 |
else { |
| 112 |
return array(); |
| 113 |
@@ -987,24 +989,27 @@ function mysql_db_get_all_row_by_steps_s |
| 114 |
* Starts a database transaction. |
| 115 |
*/ |
| 116 |
function mysql_db_process_sql_begin() { |
| 117 |
- mysql_query ('SET AUTOCOMMIT = 0'); |
| 118 |
- mysql_query ('START TRANSACTION'); |
| 119 |
+ global $config; |
| 120 |
+ mysqli_query($config['dbconnection'], 'SET AUTOCOMMIT = 0'); |
| 121 |
+ mysqli_query($config['dbconnection'], 'START TRANSACTION'); |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Commits a database transaction. |
| 126 |
*/ |
| 127 |
function mysql_db_process_sql_commit() { |
| 128 |
- mysql_query ('COMMIT'); |
| 129 |
- mysql_query ('SET AUTOCOMMIT = 1'); |
| 130 |
+ global $config; |
| 131 |
+ mysqli_query($config['dbconnection'], 'COMMIT'); |
| 132 |
+ mysqli_query($config['dbconnection'], 'SET AUTOCOMMIT = 1'); |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Rollbacks a database transaction. |
| 137 |
*/ |
| 138 |
function mysql_db_process_sql_rollback() { |
| 139 |
- mysql_query ('ROLLBACK '); |
| 140 |
- mysql_query ('SET AUTOCOMMIT = 1'); |
| 141 |
+ global $config; |
| 142 |
+ mysqli_query($config['dbconnection'], 'ROLLBACK '); |
| 143 |
+ mysqli_query($config['dbconnection'], 'SET AUTOCOMMIT = 1'); |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
@@ -1018,7 +1023,7 @@ function mysql_safe_sql_string($string) |
| 148 |
|
| 149 |
global $config; |
| 150 |
|
| 151 |
- return mysql_real_escape_string($string, $config['dbconnection']); |
| 152 |
+ return mysqli_real_escape_string($config['dbconnection'], $string); |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
@@ -1027,7 +1032,8 @@ function mysql_safe_sql_string($string) |
| 157 |
* @return string Return the string error. |
| 158 |
*/ |
| 159 |
function mysql_db_get_last_error() { |
| 160 |
- return mysql_error(); |
| 161 |
+ global $config; |
| 162 |
+ return mysqli_error($config['dbconnection']); |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
@@ -1064,9 +1070,10 @@ function mysql_get_system_time() { |
| 167 |
* @return mixed Return the type name or False in error case. |
| 168 |
*/ |
| 169 |
function mysql_db_get_type_field_table($table, $field) { |
| 170 |
- $result = mysql_query('SELECT parameters FROM ' . $table); |
| 171 |
+ global $config; |
| 172 |
+ $result = mysqli_query($config['dbconnection'], 'SELECT parameters FROM ' . $table); |
| 173 |
|
| 174 |
- return mysql_field_type($result, $field); |
| 175 |
+ return ((is_object($___mysqli_tmp = mysqli_fetch_field_direct($result, 0)) && !is_null($___mysqli_tmp = $___mysqli_tmp->type)) ? ((($___mysqli_tmp = (string)(substr(( (($___mysqli_tmp == MYSQLI_TYPE_STRING) || ($___mysqli_tmp == MYSQLI_TYPE_VAR_STRING) ) ? "string " : "" ) . ( (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_LONG, MYSQLI_TYPE_LONGLONG, MYSQLI_TYPE_INT24))) ? "int " : "" ) . ( (in_array($___mysqli_tmp, array(MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_DECIMAL, ((defined("MYSQLI_TYPE_NEWDECIMAL")) ? constant("MYSQLI_TYPE_NEWDECIMAL") : -1)))) ? "real " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_TIMESTAMP) ? "timestamp " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_YEAR) ? "year " : "" ) . ( (($___mysqli_tmp == MYSQLI_TYPE_DATE) || ($___mysqli_tmp == MYSQLI_TYPE_NEWDATE) ) ? "date " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_TIME) ? "time " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_SET) ? "set " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_ENUM) ? "enum " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_GEOMETRY) ? "geometry " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_DATETIME) ? "datetime " : "" ) . ( (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB))) ? "blob " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_NULL) ? "null " : "" ), 0, -1))) == "") ? "unknown" : $___mysqli_tmp) : false); |
| 176 |
} |
| 177 |
|
| 178 |
/** |
| 179 |
@@ -1136,11 +1143,11 @@ function mysql_db_process_file ($path, $ |
| 180 |
$query .= $sql_line; |
| 181 |
|
| 182 |
if (preg_match("/;[\040]*\$/", $sql_line)) { |
| 183 |
- if (!$result = mysql_query($query)) { |
| 184 |
+ if (!$result = mysqli_query($config['dbconnection'], $query)) { |
| 185 |
// Error. Rollback the transaction |
| 186 |
mysql_db_process_sql_rollback(); |
| 187 |
|
| 188 |
- $error_message = mysql_error(); |
| 189 |
+ $error_message = mysqli_error($config['dbconnection']); |
| 190 |
|
| 191 |
// Handle the error |
| 192 |
if ($handle_error) { |