Home > MySQL: Visual QuickStart Guide (1st Edition) > Topic

Resource id #4

Posted by sip3 
This forum is now read only. You can not log in or make any changes. Please use the new forum linked above.
As of March 14, 2011, this forum has been replaced and is permanently set to read-only mode. This means you can view any existing post but cannot open new posts or reply to existing ones. The new forum is located athttp://www.larryullman.com/forums/If you need to post a message, you'll need to register there. If you have to post in order to follow up on a thread started here, well, that's going to be a bit of a pain. I would recommend just posting the appropriate information, or copying the original text from here, or linking to your thread here. I apologize for the inconvenience but this purge will make for better forums in the long run. Thanks.
Resource id #4
December 16, 2007 03:13PM
Hi all,

i'm a new user of PHP,

at the moment, i have queries regarding the "Resource id #4"

everythings run perfectly but before the script showing the result,
it shows the "Resource id #4" in front of the result, and i don't have any clue what happend with it.

Could someone please help me with it.

thanks a lot,
regards,
adi

here is my code:

<?php
require_once('dbconnect.php');
$trackID = $_GET['TrackId'];
$trackName = mysql_query("SELECT TrackName FROM EHAC_track where TrackId='$trackID'");
$meetingList = mysql_query("SELECT MeetingID, MeetingDate FROM EHAC_meeting WHERE TrackId='$trackID' ORDER BY MeetingDate");
?>

<ul>
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
Echo $trackName;
$count = 0;
while ($row = mysql_fetch_array($meetingList)) {
Echo "<li><a href=raceInformation.php?MeetingID=".$row['MeetingID']." class=\"item-link-1\">".$row['MeetingDate']."</a></li>";
$count++;
}
if($count==0){
Echo "<span class=\"header-2\">No date available on this track</span>";
}
?>
</ul>
Re: Resource id #4
December 17, 2007 02:31PM
You're getting that because you have this line:
Echo $trackName;

So you're literally printing the value which is the result of the query.

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Re: Resource id #4
December 30, 2007 07:00PM
I have a relating question:

this code:

$res = $this->MySQLQuery($qs);
echo "----->".$res."----<br>";

echoes: ----->Resource id #20----

after it has been running through this class file (MySQL) function MySQLQuery code:

$this->dbResults = mysql_query($query, $this->dbConnect);

// mysql_num_rows — Get number of rows in result
$this->dbNumberRows = mysql_num_rows($this->dbResults);
// Let's check to see how many rows are affected
if ($this->dbNumberRows) {
// Return the results
return $this->dbResults;
}else{
// no rows found
$this->dbResults = NULL;
return $this->dbResults;

further explanation:
$this->dbNumberRows should be zero because in this case the query finds no and should find no results. It is performed to check if some records are in the db. So no rows found is a correct and useful result.

questions:
1 setting $this->dbResults to NULL does not work. I need empty or NULL but it still contains "Resource id #20". How come?
2 How do I get a NULL or FALSE result?
3 what is best practise to distinguish between an SQL error (db connection failure || query error) and rows effected / mysql_num_rows = 0

thanks for your help.

Jos

PHP 5.2.0 MySQL 5.0.27 Apache 2.0.59
Re: Resource id #4
December 31, 2007 06:43PM
> 1 setting $this->dbResults to NULL does not work.
> I need empty or NULL but it still contains
> "Resource id #20". How come?
> 2 How do I get a NULL or FALSE result?

I'm not sure what setting it to NULL isn't working but I disagree with your desire to assign it a NULL or FALSE value. As it stands, dbResults will store either a resource ID or a FALSE value, the results of running mysql_query(). A FALSE value should indicate that the query didn't run properly, as the mysql_query() function does. This should be different than an indication that it ran properly but returned no results. For that you would use your dbNumberRows.

> 3 what is best practise to distinguish between an
> SQL error (db connection failure || query error)
> and rows effected / mysql_num_rows = 0

I would use different variables, as you are doing. dbResults should have a NULL value before a query is run, a Resource ID value after running it successfully, and a FALSE value if an error occurred. dbNumberRows should have a NULL value before a query is run and a numeric value after. It sounds to me like you're trying to combine all this into one flag, which isn't a good idea.

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator
Re: Resource id #4
January 01, 2008 11:07AM
Larry,

Your reply is helpful. I will use different vars.

My best,

Jos

PHP 5.2.0 MySQL 5.0.27 Apache 2.0.59