OsakaWebbie
Programmer
I thought I was being clever, but... Throughout many PHP files I had various versions of code to do the same thing: call mysql_query(), check for a FALSE result, and exit the script while displaying part or all of the useful information (i.e. sometimes I would show the complete SQL statement, sometimes I wouldn't; sometimes I would enclose it in <pre> but most of the time I wouldn't...). So I decided to consolidate and clean it up. I have a file called functions.php that is included in all my other files, so I put this in functions.php:
Then I tried calling it in one of my main files:
But something was lost in transmission:
Code:
function sqlquery_checked($sql) {
return mysql_query($sql) or die("<pre><strong>SQL Error ".mysql_errno().": ".mysql_error()."</strong><br />($sql)</pre>");
}
Code:
$result = sqlquery_checked("SELECT stuff FROM table");
while ($row = mysql_fetch_object($result)) {
I'm assuming that the call to mysql_query succeeded, because my die call did not run. So I should have had a valid result to pass back. Are MySQL result resource pointers not passable as the return value of a function or something? Or is the query result information only visible inside my functions.php file?Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in...