views:

213

answers:

3

Consider the following 3 standard statements

$queryString = "SOME SQL SELECT QUERY";
$queryResult = mysql_query($queryString);
$queryArray = mysql_fetch_array($queryResult);

Question is :

If the result set of the query is empty, what will be the resultant datatype and value of $queryArray after all three statements are executed ?

+4  A: 

From the mysql_fetch_array manual page:

Returns an array of strings that corresponds to the fetched row, or FALSE if there are no more rows.

So the data type of the final return value would be boolean.

Gumbo
thanks a lot !
OrangeRind
OrangeRind - I would encourage you to officially "Accept" this answer if you find it to satisfactorily answer your question.
Peter Bailey
haha lol yes! surely! +1 also
OrangeRind
+1  A: 

You should Read The Fine Manual. All the mysql_fetch_* functions return false if the result set is empty. False is a boolean type, although types aren't super-important in PHP.

Maybe consider using PDO instead of mysql_*, because it (1) doesn't tie your PHP code to a particular database vendor (allowing you to test with sqlite databases, for instance), and (2) PDO is more performant than the mysql_* functions in general.

jared
A: 

you can also do

$num = mysql_num_rows($queryResult);

to find out how many rows are being returned.

Cheers

Frederico