-2

What does Resource Id #4 stand for in php when you run this a script resembling this:

$dbs = mysql_connect('localhost', 'me', 'mypass') 
OR die('Couldn\'t connect to the database: '.mysql_error());
@mysql_select_db('my_db') OR 
die('Could not connect to the database: '.mysql_error());
$query_result = mysql_query("SELECT * FROM mytable;");

Then echoing query_result? I know what you have to do

mysql_fetch_array($query_result);

to get the contents of said query's result, but I want to know what Resource Id #4 actually means.

Not A Box
  • 11
  • 3
  • 3
    It is what it says, a reference to a resource such as a mySql connection. – David Barker Jul 09 '14 at 17:54
  • 1
    It's never bad for scripters to learn the basics of assembly and a C-language first. It will let you understand these principles much easier. –  Jul 09 '14 at 17:56
  • 1
    @Allendar From an academic perspective, sure, but the priority should be on getting things done if you're in a commercial environment with deadlines. "Sorry, I need to understand this at the machine level" is not going to fly if you're six weeks behind on your project. – tadman Jul 09 '14 at 18:03

2 Answers2

1

A resource is just a pointer to an external object; in this case, a database connection. More info is here: http://www.php.net/manual/en/language.types.resource.php

By the way, do not use those functions, ever. Presumably you've copied and pasted them from a site, but it's probably 13 years old.

Community
  • 1
  • 1
miken32
  • 42,008
  • 16
  • 111
  • 154
  • Pointers will probably not make much sense if someone doesn't know what resource means ;). Guess it's a useful link tho :) –  Jul 09 '14 at 17:59
0

I think you might be looking for this: http://www.php.net/manual/en/language.types.resource.php and this: http://www.php.net/manual/en/resource.php

You are echoing out the resource which is the result of mysql_query which is a special PHP varianble type.

Jason
  • 15,017
  • 23
  • 85
  • 116