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:54
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
+?>
... ...
@@ -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.