Browse code

includes/mysqli_functions.php: change empty string to quoted NULL strings - as some entries in the database are already empty strings as well and can be easily confused otherwise

Clarissa Walker authored on 2026/11/08 11:53:51
Showing 1 changed files
... ...
@@ -113,7 +113,7 @@ function dbclose() {
113 113
 // Used to escape text being put into the database.
114 114
 function escapestring($str) {
115 115
 	global $dbconnect;
116
-   if (!is_array($str)) return $dbconnect->real_escape_string(($str===null) ? '' : $str);
116
+   if (!is_array($str)) return $dbconnect->real_escape_string(($str===null) ? "NULL" : $str);
117 117
    return array_map('escapestring', $str);
118 118
 }
119 119
 
Browse code

includes/mysqli_functions.php: mysqli_real_escape_string() does not like null entries [deprecated since PHP 8.1], so an empty string should take their place - fix

Clarissa Walker authored on 2026/11/07 13:31:24
Showing 1 changed files
... ...
@@ -113,7 +113,7 @@ function dbclose() {
113 113
 // Used to escape text being put into the database.
114 114
 function escapestring($str) {
115 115
 	global $dbconnect;
116
-   if (!is_array($str)) return $dbconnect->real_escape_string($str);
116
+   if (!is_array($str)) return $dbconnect->real_escape_string(($str===null) ? '' : $str);
117 117
    return array_map('escapestring', $str);
118 118
 }
119 119
 
Browse code

includes/mysqli_functions.php: fix typo in error debug entry

Clarissa Walker authored on 2026/10/30 17:05:55
Showing 1 changed files
... ...
@@ -60,7 +60,7 @@ function dbquery($query) {
60 60
 		}
61 61
 		else {
62 62
 			// this is very rare case. Uncomment this if you really lost what is doing. This is before pagesetup.php, so Admin is not set
63
-			//	echo "Query: " . $query . "<br />Error: " . dberror() "<br />" ;
63
+			//	echo "Query: " . $query . "<br />Error: " . dberror() . "<br />" ;
64 64
 			die(" <b>A fatal MySQL error was encountered.</b><br /> Check tableprefix. ");
65 65
 		}
66 66
 
Browse code

includes/mysqli_functions.php: further disable ONLY_FULL_GROUP_BY setting, partially bring back MYSQL40 compat - a variant of this shows up in newer eFiction 3.5.72

Clarissa Walker authored on 2026/10/27 05:16:49
Showing 1 changed files
... ...
@@ -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 = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,HIGH_NOT_PRECEDENCE'");
25 26
 
26 27
 	// comment UTF8 and uncomment UTF8MB4 if needed - especially when converted to Mod
27 28
     //mysqli_set_charset($mysqli_access, "utf8mb4");
Browse code

includes/mysqli_functions.php: disable ONLY_FULL_GROUP_BY setting - a variant of this shows up in newer eFiction 3.5.72

Clarissa Walker authored on 2026/10/26 12:42:32
Showing 1 changed files
... ...
@@ -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
 
24 26
 	// comment UTF8 and uncomment UTF8MB4 if needed - especially when converted to Mod
25 27
     //mysqli_set_charset($mysqli_access, "utf8mb4");
Browse code

admin/stories.php, includes/mysqli_functions.php: Database function changes from eFiction 3.5.72 - keep the MySQL strict mode behavior

Clarissa Walker authored on 2026/10/25 13:03:33
Showing 1 changed files
... ...
@@ -35,6 +35,12 @@ function dbconnect($dbhost, $dbuser, $dbpass, $dbname ) {
35 35
 	return $mysqli_access;
36 36
 }
37 37
 
38
+// Error text of the last statement, for diagnostics in die() strings: "(errno) message".
39
+function dberror() {
40
+	global $dbconnect;
41
+	if(!($dbconnect instanceof mysqli)) return "";
42
+	return "(".$dbconnect->errno.") ".$dbconnect->error;
43
+}
38 44
 
39 45
 function dbquery($query) {
40 46
 	global $debug, $headerSent, $dbconnect;
... ...
@@ -47,32 +53,40 @@ function dbquery($query) {
47 53
 	catch (mysqli_sql_exception $e)
48 54
 	{
49 55
 		if(function_exists('accessDenied')) {
50
-			accessDenied(_FATALERROR . (isADMIN ? "Query: " . $query . "<br />Error: (" . $dbconnect->errno . ") " . $dbconnect->error : ""));
56
+			accessDenied(_FATALERROR . (isADMIN ? "Query: " . $query . "<br />Error: " . dberror() : ""));
51 57
 		}
52
-		else {		
58
+		else {
53 59
 			// this is very rare case. Uncomment this if you really lost what is doing. This is before pagesetup.php, so Admin is not set
54
-			//	echo "Query: " . $query . "<br />Error: (" . $dbconnect->errno . ") " . $dbconnect->error  <br /> ;
55
-			die(" <b>A fatal MySQL error was encountered.</b><br /> Check tableprefix. ");	
60
+			//	echo "Query: " . $query . "<br />Error: " . dberror() "<br />" ;
61
+			die(" <b>A fatal MySQL error was encountered.</b><br /> Check tableprefix. ");
56 62
 		}
57
-			
58
-	} 
63
+
64
+	}
59 65
 	return $result;
60 66
 }
61 67
 
62 68
 function dbnumrows($query) {
63 69
 	global $debug, $dbconnect;
64 70
 	if ($query === false && $debug) {
65
-		echo "<!-- dbnumrows ".$dbconnect->error." -->\n";
71
+		echo "<!-- dbnumrows ".($dbconnect ? $dbconnect->error : "")." -->\n";
72
+	}
73
+	return $query === false ? 0 : $query->num_rows;
74
+}
75
+
76
+function dbfetcharray($query) {
77
+	global $debug, $dbconnect;
78
+	if ($query === false && $debug) {
79
+		echo "<!-- dbfetcharray ".($dbconnect ? $dbconnect->error : "")." -->\n";
66 80
 	}
67
-	return $query->num_rows;
81
+	return $query === false ? null : $query->fetch_array();
68 82
 }
69 83
 
70 84
 function dbassoc($query) {
71 85
 	global $debug, $dbconnect;
72 86
 	if ($query === false && $debug) {
73
-		echo "<!-- dbassoc ".$dbconnect->errno." -->\n";
87
+		echo "<!-- dbassoc ".($dbconnect ? $dbconnect->error : "")." -->\n";
74 88
 	}
75
-	return $query->fetch_assoc();
89
+	return $query === false ? null : $query->fetch_assoc();
76 90
 }
77 91
 
78 92
 function dbinsertid($tablename = 0) {
... ...
@@ -83,14 +97,14 @@ function dbinsertid($tablename = 0) {
83 97
 function dbrow($query) {
84 98
 	global $debug, $dbconnect;
85 99
 	if ($query === false && $debug) {
86
-		if($dbconnect->error) echo "<!-- dbrow ".$dbconnect->errno." -->\n";
100
+		if($dbconnect->error) echo "<!-- dbrow ".($dbconnect ? $dbconnect->error : "")." -->\n";
87 101
 	}
88
-	return $query->fetch_row();
102
+	return $query === false ? null : $query->fetch_row();
89 103
 }
90 104
 
91 105
 function dbclose() {
92 106
 	global $dbconnect;
93
-	$dbconnect->close();
107
+	if($dbconnect instanceof mysqli) $dbconnect->close();
94 108
 }
95 109
 
96 110
 // Used to escape text being put into the database.
Browse code

includes/mysqli_functions.php: fix copy-paste oversight in security-related MYSQLi set_charset options

Clarissa Walker authored on 2026/10/10 22:40:02
Showing 1 changed files
... ...
@@ -22,8 +22,8 @@ function dbconnect($dbhost, $dbuser, $dbpass, $dbname ) {
22 22
 	mysqli_query($mysqli_access, "SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'");
23 23
 
24 24
 	// comment UTF8 and uncomment UTF8MB4 if needed - especially when converted to Mod
25
-    //mysqli_set_charset($mysqli_access, "SET NAMES utf8mb4;");
26
-    mysqli_set_charset($mysqli_access, "utf8;");
25
+    //mysqli_set_charset($mysqli_access, "utf8mb4");
26
+    mysqli_set_charset($mysqli_access, "utf8");
27 27
 
28 28
 	// comment UTF8 and uncomment UTF8MB4 if needed - especially when converted to Mod
29 29
     //mysqli_query($mysqli_access, "SET NAMES UTF8MB4;");
Browse code

includes/mysqli_functions.php: add set_charset to query - security-related

Clarissa Walker authored on 2026/09/28 04:26:37
Showing 1 changed files
... ...
@@ -21,6 +21,10 @@ 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
 
24
+	// comment UTF8 and uncomment UTF8MB4 if needed - especially when converted to Mod
25
+    //mysqli_set_charset($mysqli_access, "SET NAMES utf8mb4;");
26
+    mysqli_set_charset($mysqli_access, "utf8;");
27
+
24 28
 	// comment UTF8 and uncomment UTF8MB4 if needed - especially when converted to Mod
25 29
     //mysqli_query($mysqli_access, "SET NAMES UTF8MB4;");
26 30
     mysqli_query($mysqli_access, "SET NAMES UTF8;");
Browse code

Database connection setting updates

Clarissa Walker authored on 2026/09/19 18:00:28
Showing 1 changed files
... ...
@@ -24,6 +24,10 @@ function dbconnect($dbhost, $dbuser, $dbpass, $dbname ) {
24 24
 	// comment UTF8 and uncomment UTF8MB4 if needed - especially when converted to Mod
25 25
     //mysqli_query($mysqli_access, "SET NAMES UTF8MB4;");
26 26
     mysqli_query($mysqli_access, "SET NAMES UTF8;");
27
+
28
+	// if SET NAMES UTF8MB4 is uncommented, uncomment this along with UTF8MB4, especially when converted to Mod
29
+	//mysqli_query($mysqli_access, "SET collation_connection = utf8mb4_bin;");
30
+
27 31
 	return $mysqli_access;
28 32
 }
29 33
 
Browse code

includes/mysqli_functions.php: add option for SET NAMES of UTF8MB4 with a note - this may especially help with old-ish server setups

Clarissa Walker authored on 2026/09/19 15:24:06
Showing 1 changed files
... ...
@@ -20,6 +20,9 @@ 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
+
24
+	// comment UTF8 and uncomment UTF8MB4 if needed - especially when converted to Mod
25
+    //mysqli_query($mysqli_access, "SET NAMES UTF8MB4;");
23 26
     mysqli_query($mysqli_access, "SET NAMES UTF8;");
24 27
 	return $mysqli_access;
25 28
 }
Browse code

3.5.8.1 warnings, dbconnect, install changes

Jimako authored on 2024/05/09 06:30:39
Showing 1 changed files
... ...
@@ -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
+?>
Browse code

3.5.6 efiction version

Jimako authored on 2024/03/09 16:09:42
Showing 1 changed files
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