| ... | ... |
@@ -103,7 +103,7 @@ function dbclose() {
|
| 103 | 103 |
// Used to escape text being put into the database. |
| 104 | 104 |
function escapestring($str) {
|
| 105 | 105 |
global $dbconnect; |
| 106 |
- if (!is_array($str)) return $dbconnect->real_escape_string(($str===null) ? '' : $str); |
|
| 106 |
+ if (!is_array($str)) return $dbconnect->real_escape_string(($str===null) ? "NULL" : $str); |
|
| 107 | 107 |
return array_map('escapestring', $str);
|
| 108 | 108 |
} |
| 109 | 109 |
|
| ... | ... |
@@ -103,7 +103,7 @@ function dbclose() {
|
| 103 | 103 |
// Used to escape text being put into the database. |
| 104 | 104 |
function escapestring($str) {
|
| 105 | 105 |
global $dbconnect; |
| 106 |
- if (!is_array($str)) return $dbconnect->real_escape_string($str); |
|
| 106 |
+ if (!is_array($str)) return $dbconnect->real_escape_string(($str===null) ? '' : $str); |
|
| 107 | 107 |
return array_map('escapestring', $str);
|
| 108 | 108 |
} |
| 109 | 109 |
|
| ... | ... |
@@ -50,7 +50,7 @@ function dbquery($query) {
|
| 50 | 50 |
} |
| 51 | 51 |
else {
|
| 52 | 52 |
// this is very rare case. Uncomment this if you really lost what is doing. This is before pagesetup.php, so Admin is not set |
| 53 |
- // echo "Query: " . $query . "<br />Error: " . dberror() "<br />" ; |
|
| 53 |
+ // echo "Query: " . $query . "<br />Error: " . dberror() . "<br />" ; |
|
| 54 | 54 |
die(" <b>A fatal MySQL error was encountered.</b><br /> Check tableprefix. ");
|
| 55 | 55 |
} |
| 56 | 56 |
|
| ... | ... |
@@ -21,7 +21,8 @@ function dbconnect($dbhost, $dbuser, $dbpass, $dbname ) {
|
| 21 | 21 |
//mysqli_query($mysql_access, "SET SESSION sql_mode = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION'"); |
| 22 | 22 |
//mysqli_query($mysqli_access, "SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'"); |
| 23 | 23 |
// MariaDB seems to disable ONLY_FULL_GROUP_BY strict mode by default - needed for MySQL 8.0 and above... |
| 24 |
- mysqli_query($mysqli_access, "SET SESSION sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'"); |
|
| 24 |
+ // HIGH_NOT_PRECEDENCE was part of MYSQL40 compat mode |
|
| 25 |
+ mysqli_query($mysqli_access, "SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION,HIGH_NOT_PRECEDENCE'"); |
|
| 25 | 26 |
mysqli_set_charset($mysqli_access, "utf8"); |
| 26 | 27 |
mysqli_query($mysqli_access, "SET NAMES UTF8;"); |
| 27 | 28 |
return $mysqli_access; |
| ... | ... |
@@ -19,7 +19,9 @@ function dbconnect($dbhost, $dbuser, $dbpass, $dbname ) {
|
| 19 | 19 |
} |
| 20 | 20 |
} |
| 21 | 21 |
//mysqli_query($mysql_access, "SET SESSION sql_mode = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION'"); |
| 22 |
- mysqli_query($mysqli_access, "SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'"); |
|
| 22 |
+ //mysqli_query($mysqli_access, "SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'"); |
|
| 23 |
+ // MariaDB seems to disable ONLY_FULL_GROUP_BY strict mode by default - needed for MySQL 8.0 and above... |
|
| 24 |
+ mysqli_query($mysqli_access, "SET SESSION sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'"); |
|
| 23 | 25 |
mysqli_set_charset($mysqli_access, "utf8"); |
| 24 | 26 |
mysqli_query($mysqli_access, "SET NAMES UTF8;"); |
| 25 | 27 |
return $mysqli_access; |
| ... | ... |
@@ -25,6 +25,12 @@ function dbconnect($dbhost, $dbuser, $dbpass, $dbname ) {
|
| 25 | 25 |
return $mysqli_access; |
| 26 | 26 |
} |
| 27 | 27 |
|
| 28 |
+// Error text of the last statement, for diagnostics in die() strings: "(errno) message". |
|
| 29 |
+function dberror() {
|
|
| 30 |
+ global $dbconnect; |
|
| 31 |
+ if(!($dbconnect instanceof mysqli)) return ""; |
|
| 32 |
+ return "(".$dbconnect->errno.") ".$dbconnect->error;
|
|
| 33 |
+} |
|
| 28 | 34 |
|
| 29 | 35 |
function dbquery($query) {
|
| 30 | 36 |
global $debug, $headerSent, $dbconnect; |
| ... | ... |
@@ -37,32 +43,40 @@ function dbquery($query) {
|
| 37 | 43 |
catch (mysqli_sql_exception $e) |
| 38 | 44 |
{
|
| 39 | 45 |
if(function_exists('accessDenied')) {
|
| 40 |
- accessDenied(_FATALERROR . (isADMIN ? "Query: " . $query . "<br />Error: (" . $dbconnect->errno . ") " . $dbconnect->error : ""));
|
|
| 46 |
+ accessDenied(_FATALERROR . (isADMIN ? "Query: " . $query . "<br />Error: " . dberror() : "")); |
|
| 41 | 47 |
} |
| 42 |
- else {
|
|
| 48 |
+ else {
|
|
| 43 | 49 |
// this is very rare case. Uncomment this if you really lost what is doing. This is before pagesetup.php, so Admin is not set |
| 44 |
- // echo "Query: " . $query . "<br />Error: (" . $dbconnect->errno . ") " . $dbconnect->error <br /> ;
|
|
| 45 |
- die(" <b>A fatal MySQL error was encountered.</b><br /> Check tableprefix. ");
|
|
| 50 |
+ // echo "Query: " . $query . "<br />Error: " . dberror() "<br />" ; |
|
| 51 |
+ die(" <b>A fatal MySQL error was encountered.</b><br /> Check tableprefix. ");
|
|
| 46 | 52 |
} |
| 47 |
- |
|
| 48 |
- } |
|
| 53 |
+ |
|
| 54 |
+ } |
|
| 49 | 55 |
return $result; |
| 50 | 56 |
} |
| 51 | 57 |
|
| 52 | 58 |
function dbnumrows($query) {
|
| 53 | 59 |
global $debug, $dbconnect; |
| 54 | 60 |
if ($query === false && $debug) {
|
| 55 |
- echo "<!-- dbnumrows ".$dbconnect->error." -->\n"; |
|
| 61 |
+ echo "<!-- dbnumrows ".($dbconnect ? $dbconnect->error : "")." -->\n"; |
|
| 62 |
+ } |
|
| 63 |
+ return $query === false ? 0 : $query->num_rows; |
|
| 64 |
+} |
|
| 65 |
+ |
|
| 66 |
+function dbfetcharray($query) {
|
|
| 67 |
+ global $debug, $dbconnect; |
|
| 68 |
+ if ($query === false && $debug) {
|
|
| 69 |
+ echo "<!-- dbfetcharray ".($dbconnect ? $dbconnect->error : "")." -->\n"; |
|
| 56 | 70 |
} |
| 57 |
- return $query->num_rows; |
|
| 71 |
+ return $query === false ? null : $query->fetch_array(); |
|
| 58 | 72 |
} |
| 59 | 73 |
|
| 60 | 74 |
function dbassoc($query) {
|
| 61 | 75 |
global $debug, $dbconnect; |
| 62 | 76 |
if ($query === false && $debug) {
|
| 63 |
- echo "<!-- dbassoc ".$dbconnect->errno." -->\n"; |
|
| 77 |
+ echo "<!-- dbassoc ".($dbconnect ? $dbconnect->error : "")." -->\n"; |
|
| 64 | 78 |
} |
| 65 |
- return $query->fetch_assoc(); |
|
| 79 |
+ return $query === false ? null : $query->fetch_assoc(); |
|
| 66 | 80 |
} |
| 67 | 81 |
|
| 68 | 82 |
function dbinsertid($tablename = 0) {
|
| ... | ... |
@@ -73,14 +87,14 @@ function dbinsertid($tablename = 0) {
|
| 73 | 87 |
function dbrow($query) {
|
| 74 | 88 |
global $debug, $dbconnect; |
| 75 | 89 |
if ($query === false && $debug) {
|
| 76 |
- if($dbconnect->error) echo "<!-- dbrow ".$dbconnect->errno." -->\n"; |
|
| 90 |
+ if($dbconnect->error) echo "<!-- dbrow ".($dbconnect ? $dbconnect->error : "")." -->\n"; |
|
| 77 | 91 |
} |
| 78 |
- return $query->fetch_row(); |
|
| 92 |
+ return $query === false ? null : $query->fetch_row(); |
|
| 79 | 93 |
} |
| 80 | 94 |
|
| 81 | 95 |
function dbclose() {
|
| 82 | 96 |
global $dbconnect; |
| 83 |
- $dbconnect->close(); |
|
| 97 |
+ if($dbconnect instanceof mysqli) $dbconnect->close(); |
|
| 84 | 98 |
} |
| 85 | 99 |
|
| 86 | 100 |
// Used to escape text being put into the database. |
| ... | ... |
@@ -20,6 +20,7 @@ function dbconnect($dbhost, $dbuser, $dbpass, $dbname ) {
|
| 20 | 20 |
} |
| 21 | 21 |
//mysqli_query($mysql_access, "SET SESSION sql_mode = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION'"); |
| 22 | 22 |
mysqli_query($mysqli_access, "SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'"); |
| 23 |
+ mysqli_set_charset($mysqli_access, "utf8"); |
|
| 23 | 24 |
mysqli_query($mysqli_access, "SET NAMES UTF8;"); |
| 24 | 25 |
return $mysqli_access; |
| 25 | 26 |
} |
| ... | ... |
@@ -4,10 +4,11 @@ |
| 4 | 4 |
if(!function_exists("dbconnect")) { // just in case. Some people seemed to be having an issue and this was the easiest fix.
|
| 5 | 5 |
|
| 6 | 6 |
function dbconnect($dbhost, $dbuser, $dbpass, $dbname ) {
|
| 7 |
- $mysql_access = new mysqli($dbhost, $dbuser, $dbpass, $dbname); |
|
| 7 |
+ $mysqli_access = new mysqli($dbhost, $dbuser, $dbpass, $dbname); |
|
| 8 |
+ |
|
| 8 | 9 |
try |
| 9 | 10 |
{
|
| 10 |
- $mysql_access = new mysqli($dbhost, $dbuser, $dbpass, $dbname); |
|
| 11 |
+ $mysqli_access = new mysqli($dbhost, $dbuser, $dbpass, $dbname); |
|
| 11 | 12 |
} |
| 12 | 13 |
catch (mysqli_sql_exception $e) |
| 13 | 14 |
{
|
| ... | ... |
@@ -18,9 +19,9 @@ function dbconnect($dbhost, $dbuser, $dbpass, $dbname ) {
|
| 18 | 19 |
} |
| 19 | 20 |
} |
| 20 | 21 |
//mysqli_query($mysql_access, "SET SESSION sql_mode = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION'"); |
| 21 |
- mysqli_query($mysql_access, "SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'"); |
|
| 22 |
- mysqli_query($mysql_access, "SET NAMES UTF8;"); |
|
| 23 |
- return $mysql_access; |
|
| 22 |
+ mysqli_query($mysqli_access, "SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'"); |
|
| 23 |
+ mysqli_query($mysqli_access, "SET NAMES UTF8;"); |
|
| 24 |
+ return $mysqli_access; |
|
| 24 | 25 |
} |
| 25 | 26 |
|
| 26 | 27 |
|
| ... | ... |
@@ -91,4 +92,4 @@ function escapestring($str) {
|
| 91 | 92 |
// End DB functions |
| 92 | 93 |
|
| 93 | 94 |
} |
| 94 |
-?> |
|
| 95 | 95 |
\ No newline at end of file |
| 96 |
+?> |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,94 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+// Some DB functions |
|
| 4 |
+if(!function_exists("dbconnect")) { // just in case. Some people seemed to be having an issue and this was the easiest fix.
|
|
| 5 |
+ |
|
| 6 |
+function dbconnect($dbhost, $dbuser, $dbpass, $dbname ) {
|
|
| 7 |
+ $mysql_access = new mysqli($dbhost, $dbuser, $dbpass, $dbname); |
|
| 8 |
+ try |
|
| 9 |
+ {
|
|
| 10 |
+ $mysql_access = new mysqli($dbhost, $dbuser, $dbpass, $dbname); |
|
| 11 |
+ } |
|
| 12 |
+ catch (mysqli_sql_exception $e) |
|
| 13 |
+ {
|
|
| 14 |
+ if (mysqli_connect_error()) |
|
| 15 |
+ {
|
|
| 16 |
+ include(_BASEDIR . "languages/en.php"); // Because we haven't got a language set yet. |
|
| 17 |
+ die(_FATALERROR . " " . _NOTCONNECTED); |
|
| 18 |
+ } |
|
| 19 |
+ } |
|
| 20 |
+ //mysqli_query($mysql_access, "SET SESSION sql_mode = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION'"); |
|
| 21 |
+ mysqli_query($mysql_access, "SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'"); |
|
| 22 |
+ mysqli_query($mysql_access, "SET NAMES UTF8;"); |
|
| 23 |
+ return $mysql_access; |
|
| 24 |
+} |
|
| 25 |
+ |
|
| 26 |
+ |
|
| 27 |
+function dbquery($query) {
|
|
| 28 |
+ global $debug, $headerSent, $dbconnect; |
|
| 29 |
+ if($debug && $headerSent) echo "<!-- $query -->\n"; |
|
| 30 |
+ $result = NULL; |
|
| 31 |
+ try |
|
| 32 |
+ {
|
|
| 33 |
+ $result = $dbconnect->query($query); |
|
| 34 |
+ } |
|
| 35 |
+ catch (mysqli_sql_exception $e) |
|
| 36 |
+ {
|
|
| 37 |
+ if(function_exists('accessDenied')) {
|
|
| 38 |
+ accessDenied(_FATALERROR . (isADMIN ? "Query: " . $query . "<br />Error: (" . $dbconnect->errno . ") " . $dbconnect->error : ""));
|
|
| 39 |
+ } |
|
| 40 |
+ else {
|
|
| 41 |
+ // this is very rare case. Uncomment this if you really lost what is doing. This is before pagesetup.php, so Admin is not set |
|
| 42 |
+ // echo "Query: " . $query . "<br />Error: (" . $dbconnect->errno . ") " . $dbconnect->error <br /> ;
|
|
| 43 |
+ die(" <b>A fatal MySQL error was encountered.</b><br /> Check tableprefix. ");
|
|
| 44 |
+ } |
|
| 45 |
+ |
|
| 46 |
+ } |
|
| 47 |
+ return $result; |
|
| 48 |
+} |
|
| 49 |
+ |
|
| 50 |
+function dbnumrows($query) {
|
|
| 51 |
+ global $debug, $dbconnect; |
|
| 52 |
+ if ($query === false && $debug) {
|
|
| 53 |
+ echo "<!-- dbnumrows ".$dbconnect->error." -->\n"; |
|
| 54 |
+ } |
|
| 55 |
+ return $query->num_rows; |
|
| 56 |
+} |
|
| 57 |
+ |
|
| 58 |
+function dbassoc($query) {
|
|
| 59 |
+ global $debug, $dbconnect; |
|
| 60 |
+ if ($query === false && $debug) {
|
|
| 61 |
+ echo "<!-- dbassoc ".$dbconnect->errno." -->\n"; |
|
| 62 |
+ } |
|
| 63 |
+ return $query->fetch_assoc(); |
|
| 64 |
+} |
|
| 65 |
+ |
|
| 66 |
+function dbinsertid($tablename = 0) {
|
|
| 67 |
+ global $dbconnect; |
|
| 68 |
+ return $dbconnect->insert_id; |
|
| 69 |
+} |
|
| 70 |
+ |
|
| 71 |
+function dbrow($query) {
|
|
| 72 |
+ global $debug, $dbconnect; |
|
| 73 |
+ if ($query === false && $debug) {
|
|
| 74 |
+ if($dbconnect->error) echo "<!-- dbrow ".$dbconnect->errno." -->\n"; |
|
| 75 |
+ } |
|
| 76 |
+ return $query->fetch_row(); |
|
| 77 |
+} |
|
| 78 |
+ |
|
| 79 |
+function dbclose() {
|
|
| 80 |
+ global $dbconnect; |
|
| 81 |
+ $dbconnect->close(); |
|
| 82 |
+} |
|
| 83 |
+ |
|
| 84 |
+// Used to escape text being put into the database. |
|
| 85 |
+function escapestring($str) {
|
|
| 86 |
+ global $dbconnect; |
|
| 87 |
+ if (!is_array($str)) return $dbconnect->real_escape_string($str); |
|
| 88 |
+ return array_map('escapestring', $str);
|
|
| 89 |
+} |
|
| 90 |
+ |
|
| 91 |
+// End DB functions |
|
| 92 |
+ |
|
| 93 |
+} |
|
| 94 |
+?> |
|
| 0 | 95 |
\ No newline at end of file |