Jump to content

Crazy Error: "supplied argument is not a valid MySQL resource"


Thread7

Recommended Posts

I get an error where running a query.  I done this type of thing many many times so I don't know why this particular one is giving me trouble.  The query is inside a loop so it runs 6 times.  Every time PHP spits out this warning:

---

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in MyPHPPage.php on line 74.

---

But the weirdest thing is that the query runs fine.  Because my script shows values that are obtained from this query without any problem.  I've seen other posts in this forum where the programmer has a similar error, but none where it is just a warning and the script is executing fine.  Here is the pertinent area of code.

......

      $entryid = $weekrow['entryid'];

      $pnsql = "SELECT pickname from entries where entryid=$entryid";

      $pnresult = dbquery($pnsql);

      $pnrow = mysql_fetch_assoc($pnresult);  //This is line 74 where it says I have a problem.

      echo $pnrow['pickname'];  //This line executes just fine showing the correct value of the pickname entry in the table.

......

 

Thank you.

Sorry.  dbquery is just a way to show a friendly error message to users.  I'll post the function below.

Basically it should run mysql_query($pnsql);

 

function dbquery($q,$req = true) {

static $dbase = null;

if ( !$dbase ) {

$dbase = mysql_connect( DBHOST, DBUSER, DBPASS );

if ( $dbase ) {

$status = mysql_select_db( DBNAME );

if ( !$status ) {

$dbase = null;

}

}

if ( !$dbase ) {

if ( $req == true ) {

require_once 'pages/ErrorPage.php';

$err = new ErrorPage();

$err->$errortext = '

<!--

mysql_error '.mysql_error().'

-->

The database is temporarily unavailable.

';

$err->display();

exit;

} else {

return false;

}

}

}

return mysql_query($q);

}

odds are you are returning the string "resource id #4" for example in your function instead of a link to said resource, thus you can't access the mysql resource made from the query and thus the error is true you don't have a valid mysql resource.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.