bodybuzz Posted July 2, 2008 Share Posted July 2, 2008 My head is now hurting after a full day of banging on the wall/desk/floor.... I have worked with PHP in a MSSQL environment with no issues for some time now. I am working on a new project with mySQL as the backend and can't seem to make it jive. ENVIRONMENT: Hosted Linux / Apache 1.3.39 / PHP 4.4.7 / MySQL 4.1.22 TABLE DEF: CREATE TABLE tb_news ( newsid bigint(20) AUTO_INCREMENT NOT NULL, newsdate datetime NOT NULL DEFAULT '0000-00-00 00:00:00', newstext text NOT NULL, newsactive int(11) NOT NULL DEFAULT '1', PRIMARY KEY(newsid) ) TABLE DATA (SELECT * FROM tb_news) newsid newsdate newstext newsactive --------- -------------------- ---------------------------------------- ------------- 8 1/1/2008 1:00:00 AM test one of three, test has just begun 1 9 3/5/2008 11:14:00 AM test two of three, test continues 1 10 5/8/2008 5:43:00 PM test three of three, and now we are done 1 3 record(s) selected [Fetch MetaData: 62/ms] [Fetch Data: 0/ms] PHP CODE: <?php error_reporting(E_ALL); $con = mysql_connect("localhost", "username", "password"); mysql_select_db("databasename") || die(mysql_error()); $query = "SELECT newsid, newsdate, newstext, newsactive FROM tb_news"; $result = mysql_query($query, $con) || die(mysql_error()); //THE CODE FAILS HERE $row = mysql_fetch_row($result) || die(mysql_error()); ?> The error message that is returned is: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home3/username/public_html/domain/newsparser.php on line 12 I have tried about a hundred permutations of this code to try to get it to work and now have cut it to the absolute core to no avail... i know this is basic stuff, but i am really missing what i am missing...(?) ??? At this point, the bruise on my head (from hitting it against the wall and the desk) is starting to bleed heavily, any help would be much appreciated.. Please let me know if more info is needed.. Quote Link to comment Share on other sites More sharing options...
fenway Posted July 2, 2008 Share Posted July 2, 2008 I thought it was mysql_fetch_assoc().... Quote Link to comment Share on other sites More sharing options...
bodybuzz Posted July 2, 2008 Author Share Posted July 2, 2008 I get the same issue, whether i use: mysql_fetch_row mysql_fetch_assoc mysql_fetch_array With the mysql_fetch_assoc, the error is: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home3/username/public_html/domain/newsparser.php on line 12 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 2, 2008 Share Posted July 2, 2008 "||" is not the same as "or" Using - mysql_function_call || die(....) causes the value of the expression on the left to be OR'ed with the value of the expression on the right and the resultant logical value is returned. Using - mysql_function_call or die(....) causes the right-hand expression to be evaluated only when the left-hand expression is false. Change || to or Also, putting a die(mysql_error()) statement on a mysql_fetch_xxxxx() statement has little meaning. A mysql_fetch_xxxxxx() statement does not set a mysql_error() value so nothing will be output by the die() statement and anytime there are no rows (mysql_fetch_xxxxx returns a false), the code will die. Quote Link to comment Share on other sites More sharing options...
fenway Posted July 2, 2008 Share Posted July 2, 2008 "||" is not the same as "or" They have different precedence, that's all -- if you wrap the RHS of an || in parens, it will be the same as "or". Otherwise, they're the same. Quote Link to comment Share on other sites More sharing options...
bodybuzz Posted July 2, 2008 Author Share Posted July 2, 2008 And the healing begins. Thanks so much PFMaBiSmAd!!!! Quote Link to comment 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.