tboyer Posted December 22, 2008 Share Posted December 22, 2008 I know you folks have seen this topic before. I've found a dozen solutions to the problem, and none of them apply to me. I've been staring at the code for three days now, and I KNOW it's something stupid - I just can't see where. I've put in error reporting; I've simplified the query so that it's just getting everything; I've eliminated the loop in the hope of getting back just one row. Nothing works. Assistance greatly appreciated. PHP 5.1.6 on a RHEL5.2 system. I'm trying to do something very, very simple: [tim@melbourne www.denmantire.com]$ cat test.php #! /usr/bin/php <?php $db_user="apache"; $db_name="shipto"; $db_pass="REDACTED"; $conn = mysql_connect("localhost", $db_user, $db_pass); if (!$conn) { die('Not connected : ' . mysql_error()); } $db_selected=mysql_select_db($db_name, $conn); if (!$db_selected) { die ('Can\'t use $db_name : ' . mysql_error()); } $query = "SELECT * FROM shipto_data_2;"; $result = "mysql_query($query, $conn)"; if (!$result) { die ('Could not successfully run query ($result) from DB: ' . mysql_error()); } if ($row = mysql_fetch_assoc($result)) { return $row; } else { die ('Could not getch row from DB:' . mysql_error()); } ?> [tim@melbourne www.denmantire.com]$ ./test.php PHP Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/www/www.denmantire.com/test.php on line 28 Could not getch row from DB: The mysql commands work manually: [tim@melbourne www.denmantire.com]$ mysql --database shipto -pREDACTED -u apache Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 99 Server version: 5.0.45 Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> SELECT * FROM shipto_data_2; ... +---------------+--------------------------------+-----------------+--------------+------------+------------------+-----------------+ 673 rows in set (0.00 sec) Link to comment https://forums.phpfreaks.com/topic/138029-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-resource/ Share on other sites More sharing options...
trq Posted December 22, 2008 Share Posted December 22, 2008 You never actually execute your query. All you do is save the string "mysql_query($query, $conn)" into a variable called $result. Change this... $result = "mysql_query($query, $conn)"; to.... $result = mysql_query($query, $conn); Link to comment https://forums.phpfreaks.com/topic/138029-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-721462 Share on other sites More sharing options...
tboyer Posted December 22, 2008 Author Share Posted December 22, 2008 And I would have stared at that code the rest of my life and never seen the quotes. Thanks _very_ much... Link to comment https://forums.phpfreaks.com/topic/138029-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-721468 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.