BigMonkey Posted January 7, 2010 Share Posted January 7, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/187620-mysql_fetch_row-warning/ Share on other sites More sharing options...
Mchl Posted January 7, 2010 Share Posted January 7, 2010 || is not the same as 'or' $result = mysql_query($query, $conn) or die(mysql_error().": $query"); Quote Link to comment https://forums.phpfreaks.com/topic/187620-mysql_fetch_row-warning/#findComment-990544 Share on other sites More sharing options...
Maq Posted January 7, 2010 Share Posted January 7, 2010 You also shouldn't handle errors that way. Read more here: http://www.phpfreaks.com/blog/or-die-must-die Quote Link to comment https://forums.phpfreaks.com/topic/187620-mysql_fetch_row-warning/#findComment-990567 Share on other sites More sharing options...
BigMonkey Posted January 7, 2010 Author Share Posted January 7, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/187620-mysql_fetch_row-warning/#findComment-990594 Share on other sites More sharing options...
RaythMistwalker Posted January 7, 2010 Share Posted January 7, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/187620-mysql_fetch_row-warning/#findComment-990596 Share on other sites More sharing options...
BigMonkey Posted January 7, 2010 Author Share Posted January 7, 2010 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!? Quote Link to comment https://forums.phpfreaks.com/topic/187620-mysql_fetch_row-warning/#findComment-990599 Share on other sites More sharing options...
RaythMistwalker Posted January 7, 2010 Share Posted January 7, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/187620-mysql_fetch_row-warning/#findComment-990606 Share on other sites More sharing options...
Mchl Posted January 7, 2010 Share Posted January 7, 2010 In fact they both can be used in place of each other in many places. However in some specific application it is essential to know, that or has higher precedence than || http://www.php.net/manual/en/language.operators.precedence.php Quote Link to comment https://forums.phpfreaks.com/topic/187620-mysql_fetch_row-warning/#findComment-990628 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.