mySQL/php question (beginner)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

mySQL/php question (beginner)

Post by Coco »

just wanting to check so i know what sort of a load im putting on my sql server...
does mysql_fetch_array() make any calls to the database? or is all the data from the query statement stored by php on the webserver?
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

It does call to database I think... mysql_query() returns the Reource ID and mysql_fetch_array() fetches the field(s) from it.
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post by MattF »

when you do a mysql_query() and assign it to a variable the contents of the variable is the return from the query. mysql_fetch_array() converts the data to an array and returns it, I think it does this simply from the data in the string without querying the database.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

But don't they get the value of fields from the db? And that's not what mysql_query do is it?
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post by MattF »

mysql_query performs a query and if it is SELECT,SHOW,EXPLAIN or DESCRIBE it returns a resource identifier, i think this identifies the place in the memory that the result has been saved in. mysql_fetch_array() then finds the data described by the resource identifier and fetches it as an array. This is the best I can judge from reading the manual.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Mmmmm got to find it out...!
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

guess it aint such a beginner question after all 8O
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

The answer (as always) is: it depends :D

php_mysql.c :

Code: Select all

if(use_store == MYSQL_USE_RESULT) {
	mysql_result=mysql_use_result(&mysql->conn);
} else {
	mysql_result=mysql_store_result(&mysql->conn);
}
and 8.4.3.217 mysql_use_result()
mysql_use_result() initiates a result set retrieval but does not actually read the result set into the client like mysql_store_result() does. Instead, each row must be retrieved individually by making calls to mysql_fetch_row().
afaik the only function that uses use_result() is mysql_unbuffered_query
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

So deos it mean it won't access the MYSQL db?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

seems so. Whenever you call mysql_query the php-module also calls mysql_store_result, transfering the whole result data to the client.
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

volka wrote:
mysql_use_result() initiates a result set retrieval but does not actually read the result set into the client like mysql_store_result() does. Instead, each row must be retrieved individually by making calls to mysql_fetch_row().
does "client" refer to the webserver running the php module or the client browser?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Browser. :)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

don't let Oromian take you a ride :D
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

lolz~

:wink:
Post Reply