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 2 changed files
1 1
old mode 100644
2 2
new mode 100755
... ...
@@ -32,7 +32,7 @@ function featured( ) {
32 32
 	if($_GET['feature'])
33 33
 		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET featured = 1 WHERE sid = ".$_GET['feature']);
34 34
 	$fquery = "SELECT stories.*, stories.title as title, author.penname, DATE_FORMAT(FROM_UNIXTIME(stories.updated), '%Y.%m.%d') as updatesort, DATE_FORMAT(stories.date, '$datim') as date, DATE_FORMAT(FROM_UNIXTIME(stories.updated), '$datim') as updated FROM ".TABLEPREFIX."fanfiction_authors as author, ".TABLEPREFIX."fanfiction_stories as stories WHERE stories.featured > 0 AND stories.uid = author.uid ORDER BY stories.featured";
35
-	$fresult = dbquery($fquery) or die(_FATALERROR."Query: ".$fquery."<br />Error: (". $dbconnect->errno.") ". $dbconnect->error);
35
+	$fresult = dbquery($fquery) or die(_FATALERROR."Query: ".$fquery."<br />Error: ".dberror());
36 36
 	$output = "<center><table class=\"tblborder\" cellpadding=\"5\"><tr><th colspan=\"2\" align=\"center\">"._FEATUREDSTORIES."</th></tr>";
37 37
 	if(!dbnumrows($fresult)) $output .= "<tr><td colspan=\"2\" align=\"center\">"._NOSTORIES."</td><tr>";
38 38
 	while($story = dbassoc($fresult)) {
... ...
@@ -48,7 +48,7 @@ function submitted()
48 48
 	global $tableprefix, $admincats, $allowed_tags, $dbconnect;
49 49
 		$output = "<center><h4>"._SUBMITTED."</h4></center>";
50 50
 		$query = "SELECT story.title as storytitle, chapter.uid, chapter.sid, story.catid, chapter.chapid, chapter.inorder, chapter.title, author.penname FROM (".TABLEPREFIX."fanfiction_chapters as chapter, ".TABLEPREFIX."fanfiction_authors as author) LEFT JOIN ".TABLEPREFIX."fanfiction_stories as story ON story.sid = chapter.sid WHERE chapter.validated = '0' AND chapter.uid = author.uid ORDER BY story.title ASC, chapter.inorder ASC";
51
-		$result = dbquery($query) or die(_FATALERROR."Query: ".$query."<br />Error: (". $dbconnect->errno.") ". $dbconnect->error);
51
+		$result = dbquery($query) or die(_FATALERROR."Query: ".$query."<br />Error: ".dberror());
52 52
 		$output .= "<table class=\"tblborder\" cellspacing=\"0\" cellpadding=\"3\" align=\"center\"><tr class=\"tblborder\"><th>"._TITLE."</th><th>"._AUTHOR."</th><th>"._CATEGORY."</th><th>"._OPTIONS."</th></tr>";
53 53
 		$array = explode(",", $admincats);
54 54
 		while ($story = dbassoc($result))
... ...
@@ -238,4 +238,4 @@ function noletter( ) {
238 238
 }
239 239
 // end noletter
240 240
 
241
-?>
242 241
\ No newline at end of file
242
+?>
... ...
@@ -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.