Jump to content

mysql_fetch_row() warning


BigMonkey

Recommended Posts

This warning/error started about 2 days ago.  Only one change has occurred on the server, and that is a change in the password.  The script should fail long before it get to its current failure point if the password were the issue.

 

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$dbname = 'nameofdb';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname, $conn) or die('Error selecting DB.');
$query  = "SELECT * FROM news_items";
$result = mysql_query($query, $conn) || die('Failed Query');

// Following line gives error "Warning...supplied argument is not a valid MySQL result resource..."
print_r(mysql_fetch_row($result));
?>

 

I started with an only slightly more complex query and reduced its complexity until I had what is here.  I verified that the script:

*  fails to connect to db if the password is changed to be incorrect,

*  fails to select the db if the name of the db is changed to be incorrect, and

*  fails to query the db if syntax errors are introduced into the query string.

 

I have restarted the services hoping that might help, but it did not.

 

Versions:

WAMP5: Apache 2.2.6, MySQL 5.0.45, PHP 5.2.5

 

I have queried a number of time in the past without incident, so I'm confident that there error is something small, overlooked coding error or something.

 

The error seems to indicate that there is something wrong with the query, but I don't see it.  In case it matters, there *is* data in the database, so there is actually something to query.  Does anything stand out for you?

 

Thanks!

 

Link to comment
https://forums.phpfreaks.com/topic/187620-mysql_fetch_row-warning/
Share on other sites

Thanks!

 

|| is not the same as 'or'

 

That fixed it.  I don't know why I thought is was the same, but I'll be reading about that more.

 

You also shouldn't handle errors that way.  Read more here:

 

http://www.phpfreaks.com/blog/or-die-must-die

 

I will also be reading about this. 

 

Thank you for the BRIEF responses without the clutter of unnecessarily technical details.

Thanks!

 

|| is not the same as 'or'

 

That fixed it.  I don't know why I thought is was the same, but I'll reading about that more.

 

You also shouldn't handle errors that way.  Read more here:

 

http://www.phpfreaks.com/blog/or-die-must-die

 

I will also be reading about this. 

 

Thank you for the BRIEF responses with the clutter of unnecessarily technical details.

 

You possibly thought it was the same because in some scripting languages || means or.

You possibly thought it was the same because in some scripting languages || means or.

 

Probably, but at least I should be consistent about it, right!?  :)

 

yh i guess lol. untill i read this thread i didnt see it as a problem in your code cos on of the scripting languages i know uses it.

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.