| ... | ... |
@@ -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 |