Re: [PHP] Fetch Array Problem

2003-05-27 Thread CPT John W. Holmes
Your query more than likely failed. If you had proper error checking, you'd
of seen this already. Check mysql_error() after your query to see what the
error is:

$rs = mysql_query($query) or die(mysql_error());

or

$rs = mysql_query($query);
if($e = mysql_error())
{ echo Error occurred: $e; }

etc...

---John Holmes...

- Original Message -
From: Todd Barr [EMAIL PROTECTED]
To: [EMAIL PROTECTED] [EMAIL PROTECTED]
Sent: Tuesday, May 27, 2003 10:49 AM
Subject: [PHP] Fetch Array Problem


Morning

We recently moved out site to a new server, and scripts that use to work, no
longer do.

Like mysql_fetch_array worked fine, but now I am getting this error

mysql_fetch_array(): supplied argument is not a valid MySQL result resource

Any ideas?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Fetch Array Problem

2003-05-27 Thread Philip Olson
On Tue, 27 May 2003, Todd Barr wrote:

 Morning
 
 We recently moved out site to a new server, and scripts that use to work, no longer 
 do.
 
 Like mysql_fetch_array worked fine, but now I am getting this error
 
 mysql_fetch_array(): supplied argument is not a valid MySQL result resource 
 
 Any ideas?

mysql_error() is your best friend, utilize this friendship.
See http://www.php.net/mysql-fetch-assoc for example uses.

Basically, mysql_query() returns false on failure instead
of a mysql resource, I am guessing you are trying to use
this value of false like a resource ... don't do that :)

  $sql = SELECT foo,bar FROM bleh;
  $result = mysql_query($sql);

$result will be a result OR false, let's check for that
using a simple example:

  if (!$result) {
  print Could not run query ($sql):  . mysql_error();
  exit;
  }

This way we don't use a bogus $result later in the code, 
like with one of the fetch functions.  May as well check 
the number of returned rows too:

  if (mysql_num_rows($result)  1) {
  print No rows to fetch, silly.;
  exit;
  }

We're about ready to fetch some data from $result now :)

Regards,
Philip


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php