Page 1 of 1

mySQL/php question (beginner)

Posted: Sun Sep 08, 2002 10:39 am
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?

Posted: Sun Sep 08, 2002 12:27 pm
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.

Posted: Sun Sep 08, 2002 1:54 pm
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.

Posted: Sun Sep 08, 2002 2:03 pm
by Takuma
But don't they get the value of fields from the db? And that's not what mysql_query do is it?

Posted: Sun Sep 08, 2002 2:29 pm
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.

Posted: Sun Sep 08, 2002 2:36 pm
by Takuma
Mmmmm got to find it out...!

Posted: Sun Sep 08, 2002 5:35 pm
by Coco
guess it aint such a beginner question after all 8O

Posted: Sun Sep 08, 2002 9:02 pm
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

Posted: Mon Sep 09, 2002 1:07 am
by Takuma
So deos it mean it won't access the MYSQL db?

Posted: Mon Sep 09, 2002 1:20 am
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.

Posted: Mon Sep 09, 2002 6:26 am
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?

Posted: Mon Sep 09, 2002 7:27 am
by m3mn0n
Browser. :)

Posted: Mon Sep 09, 2002 10:12 am
by volka
don't let Oromian take you a ride :D

Posted: Mon Sep 09, 2002 10:39 am
by m3mn0n
lolz~

:wink: