简体   繁体   中英

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 ?

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 .

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.

you can also do

$num = mysql_num_rows($queryResult);

to find out how many rows are being returned.

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM