返回mysql_fetch_array()的数据和类型

时间:2022-10-05 16:32:24

Consider the following 3 standard statements

请考虑以下3个标准陈述

$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 ?

如果查询的结果集为空,那么在执行所有三个语句之后,结果数据类型和$ queryArray的值是什么?

3 个解决方案

#1


From the mysql_fetch_array manual page:

从mysql_fetch_array手册页:

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

返回与获取的行对应的字符串数组,如果没有更多行,则返回FALSE。

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

因此,最终返回值的数据类型将是布尔值。

#2


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.

你应该阅读精细手册。如果结果集为空,则所有mysql_fetch_ *函数都返回false。 False是一种布尔类型,尽管类型在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.

也许考虑使用PDO而不是mysql_ *,因为它(1)不会将您的PHP代码绑定到特定的数据库供应商(例如,允许您使用sqlite数据库进行测试),以及(2)PDO比mysql_更高性能*功能一般。

#3


you can also do

你也可以

$num = mysql_num_rows($queryResult);

$ num = mysql_num_rows($ queryResult);

to find out how many rows are being returned.

找出返回的行数。

Cheers

#1


From the mysql_fetch_array manual page:

从mysql_fetch_array手册页:

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

返回与获取的行对应的字符串数组,如果没有更多行,则返回FALSE。

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

因此,最终返回值的数据类型将是布尔值。

#2


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.

你应该阅读精细手册。如果结果集为空,则所有mysql_fetch_ *函数都返回false。 False是一种布尔类型,尽管类型在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.

也许考虑使用PDO而不是mysql_ *,因为它(1)不会将您的PHP代码绑定到特定的数据库供应商(例如,允许您使用sqlite数据库进行测试),以及(2)PDO比mysql_更高性能*功能一般。

#3


you can also do

你也可以

$num = mysql_num_rows($queryResult);

$ num = mysql_num_rows($ queryResult);

to find out how many rows are being returned.

找出返回的行数。

Cheers