Jump to content

[SOLVED] supplied argument is not a valid MySQL result resource


bodybuzz

Recommended Posts

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..

Link to comment
Share on other sites

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

Link to comment
Share on other sites

"||" 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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.