OrangeRind
OrangeRind

Reputation: 4818

Return Data and Type of mysql_fetch_array()

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 ?

Upvotes: 1

Views: 2808

Answers (3)

Petrogad
Petrogad

Reputation: 4423

you can also do

$num = mysql_num_rows($queryResult);

to find out how many rows are being returned.

Cheers

Upvotes: 0

jared
jared

Reputation: 1451

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.

Upvotes: 1

Gumbo
Gumbo

Reputation: 655239

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.

Upvotes: 4

Related Questions