What does Resource id #7 means?


I tried to echo my select query to see what it looks like.

$modify_qry = mysql_query("SELECT * FROM $table WHERE pid=$pid");
echo $modify_qry ;

and here is what I got:
Resource id #7
what does this mean?
all the variable in the select query are present. Thanks!


$modify_qry = mysql_query(“SELECT * FROM ‘$table’ WHERE pid=‘$pid’”);
$modify_qry ;

If you want to echo your query, try it like this:

$qry = "SELECT * FROM $table WHERE pid=$pid";
echo $qry;

The New Guy,

Single quoting the vars isn’t necessary and will return the same result. You can’t echo the the result of an executed query directly and expect to see the query results. mysql_query returns a result id. Hence the output chafikb was getting. :slight_smile:

I tried the new guys method and got this error
Error retrieving information from database!
Error: You have an error in your SQL syntax near ‘‘african’ WHERE pid=‘1’’ at line 1
give me a sec to try Messiah’s.

Is the resource id a notice?

Edit: Try taking the single quotes of the table name.

Isn’t the resource id a value in an array?

Yah it is, sorry, I havn’t messed with php in almost 6 months now. I am very rusty. Though I get Resource ID 2 when trying to replicate the error ;).

I got it to work… Thanks much for the help guys :slight_smile:

You have to mysq_fetch’it, the ressource id is just the query id (I think) :stuck_out_tongue:

Yep, correct. You can’t simply echo the result, it isn’t in any… “form” (not an array/string etc., although you can make a multi dimensional array from it).

Now, what’s the difference between all the mysql_fetch_*?
I always used mysql_fetch_array through a while loop… (That question sound newbie eh? :D)

mysql_fetch_row only returns array with numeric keys (0 meaning the first column you asked for in the query, 1 the second etc.)
mysql_fetch_assoc only returns array with string hashes or what ever it is called, so it returns the name of the column, not the order.


$rslt = mysql_query('SELECT colA, colB, colC FROM Table LIMIT 1');
$row1 = mysql_fetch_assoc($rslt);
//lets say then that I didn't have the line above, will then not go to the next line, but just use the first.
//while loop isn't needed since I have LIMIT 1
$row2 = mysql_fetch_row($rslt);
//then $row1[0] = $row2['colA']; $row1[1] = $row2['colB'] and $row1[2] = $row2['colC']

Hope you understand this…

What would return print_r($row1) ?
Going to make a little test script, thanks for your explanation
The examples on php.net aren’t that clear :slight_smile:

print_r($row1) would return something like

Array( [0] => 'value of column A'
[1] => 'value of column B'
[2] => 'value of column C');

if I remember the syntax of print_r correctly :wink:

I see now…reference for the other newbies out there :p:
Query I ran (from IPB):

$query = mysql_query(‘SELECT macro_value, macro_replace FROM ibf_macro WHERE macro_set=5 LIMIT 1’);

mysql_fetch_assoc($result) / mysql_fetch_array($result, MYSQL_ASSOC)


	[macro_value] => C_ON_CAT
	[macro_replace] => New Posts

mysql_fetch_row($result) / mysql_fetch_array($result, MYSQL_NUM)

    [0] => C_ON_CAT
    [1] => New Posts

mysql_fetch_array($result, MYSQL_BOTH)
Would return both:

    [0] => C_ON_CAT
    [macro_value] => C_ON_CAT
    [1] => New Posts
    [macro_replace] => New Posts

Now, what’s faster? mysql_fetch_assoc($result) or mysql_fetch_array($result, MYSQL_ASSOC)? :blush:

and then again

So it seems that ordered from fastest to slowest it would be like this:
Although you could argue about the order of the last two I would say [fphp]mysql_fetch_array[/fphp] is slower since it outputs more data.

Then again the difference isn’t enough to worry about :wink:

Indeed, little faster :wink:
Any comment on mysql_num_rows vs incrementing a variable ($rows[‘rows’]++) vs count($rows)
I made a little benchmark script but the results are various…

($rows is inside a while loop with mysql_fetch_assoc)

well, I suppose mysql_num_rows is propably the best, I would be suprised if the php development team didn’t always try to make functions faster then you could by actually creating it yourself ;). Another thing is that it makes much cleaner code, to use mysql_num_rows, and pretty and clean are often more important then having it a bit faster.

Well, it’s important for the size of the board i run :wink: