Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 21st, 2004, 07:25 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default Resource id codes

I have had a look on the main PHP website and am unable to find an explanation on the Resource ID codes that appear when I echo out SQL statements.

Does anyone know where I can find what Resource id message means? (e.g. Resource id #8)

Cheers.

Michael.
__________________
Michael.
 
Old July 21st, 2004, 08:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

REsource is like a file handle, or a pointer to a resource. Tyring to access or print out the resource itself simply returns the resource number.

Say you want to query a database:

$query = "SELECT some,stuff FROM table WHERE criteria='true'";
$result = mysql_result($query);

$result is a resource (a multidimensional array, in fact):

resource = (
1 => array(
some => 'foo',
stuff => 'bar'),
1 => array(
some => 'foo2',
stuff => 'bar2'),
etc....)

But the array is only pointed to by its resource id, and so you can't print it directly.

You'd retrieve values from it via a call such as:

//mysql_fetch_assoc retrieves each subarray, representing a row, as an associative 1-dimensional array
while($row = mysql_fetch_assoc($result)){
  echo "some equals " . $row['some'] . "<br />";
  echo "stuff equals " . $row['stuff'] . "<br />";
}

(prints out:
    some equals foo
    stuff equals bar
    some equals foo2
    stuff equals bar2
and so on)

Does that help?

Dan
 
Old July 21st, 2004, 08:17 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Right I see.

The result from my query that i'm trying to get working, is coming from the $result, (from your example).

Michael.
 
Old July 21st, 2004, 09:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Kind of.

mysql_query() generates both the resource itself and the resource ID which can be used as a shorthand to identify it. Convention, generally, is that we store this number in a variable called something like $result. $result can then be used to fetch all sorts of things about the resource - such as:

mysql_num_rows($result) - "how many rows were returned?"
mysql_num_fields($result) - "how many fields were returned?"
mysql_field_name($result,$i) - "what's the name of the ith column returned?"

...and so on.

Similarly, the resource identifier representing your actual database connection (let's assume he's called $connection) can be used to find out similar esoteria, regarding your database connection. For example:

mysql_thread_id($connection) - "what's the ID value of the currently running thread (a kind of 'whomami' for database execution threads)?"

...and:

mysql_client_encoding($connection) - "what characterset is currently being used?"

HTH
Take it easy,
dan




Similar Threads
Thread Thread Starter Forum Replies Last Post
Resource For Controls Muhammad Zeeshan ASP.NET 2.0 Professional 0 July 27th, 2007 04:45 AM
'this.ID = id;' in class construction holf BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 October 6th, 2006 10:58 AM
Calendar as a resource?? kabucek BOOK: Access 2003 VBA Programmer's Reference 0 August 8th, 2006 07:27 AM
resource not available: servlets ejmelious Apache Tomcat 0 May 19th, 2005 11:52 AM
why not index.asp?id=1 can be www.myweb.com/?id=1 BurhanKhan Classic ASP Professional 11 September 6th, 2004 02:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.