PDA

View Full Version : Resource id #3 - mysql


tadziu
10-25-03, 03:34 PM
When I do this :

$fn = tom;
$query = "INSERT INTO users (first_name) VALUES ( '$fn')";
$result = @mysql_query($query);
print_r($query); echo "<br>";
print_r($result); echo "<br>";

I get this:

INSERT INTO users (first_name) VALUES ( 'tom')
1

This way it works ok.
*********

$query = "SELECT * FROM users WHERE (first_name = '$fn') ";
$result = @mysql_query($query);
print_r($query); echo "<br>";
print_r($result); echo "<br>";

I get this:

SELECT * FROM users WHERE (first_name= 'tom')
Resource id #3

What is this result? (Resource id #3)
************************************************** ***************************************

Any ideas why I get the Resource id #3 result when I do a SELECT?
.

thanks in advance

Nino
10-25-03, 03:46 PM
It looks like it's doing what it's supposed be doing.
mysql_query returns a "query identifier" if successful or false if unsuccessful. I believe the resource id would be used internally by php in subsequent operations, such as when you have a recordset returned as a result of the query and you want to loop through it.
SELECT can return a result containing data.
INSERT does not return a result, it just returns success (1) or failure (0)



From the PHP help file:

************
msql_query() sends a query to the currently active database on the server that's associated with the specified link identifier. If the link identifier isn't specified, the last opened link is assumed. If no link is open, the function tries to establish a link as if msql_connect() was called, and use it.

Returns a positive mSQL query identifier on success, or FALSE on error.
***************

tadziu
10-25-03, 04:38 PM
thanks, tadziu