如何处理从php中的sql返回的1个值

时间:2022-10-24 21:10:44

$query = "SELECT val FROM table WHERE id = 1"; mysql_query($query);

$ query =“SELECT val FROM table WHERE id = 1”;的mysql_query($查询);

This returns a single peice of data from the database. all the ways I know how to deal with this data are mysql_fetch_array() and mysql_fetch_assoc() is there a way to deal with 1 peice of data that doesn't involve pulling it into an array?

这将从数据库返回一个数据。我知道如何处理这些数据的所有方法是mysql_fetch_array()和mysql_fetch_assoc()有没有办法处理1个不涉及将其拉入数组的数据?

3 个解决方案

#1


There is mysql_fetch_field which appears to do what you want.

有mysql_fetch_field似乎可以做你想要的。

mysql_fetch_field(0,0);

#2


Many wrapper libraries offer this, for example, with ADODb, it's simple

许多包装器库提供了这种功能,例如ADODb,它很简单

$value=$db->GetOne("select val from table where id=1");

It's not hard to roll your own either.

也不难推出自己的产品。

#3


You can use mysql_result() like this;

你可以像这样使用mysql_result();

mysql_result(mysql_query($query), 0, 0);

The second parameter selects the row, and the third is the field number.

第二个参数选择行,第三个参数是字段编号。

#1


There is mysql_fetch_field which appears to do what you want.

有mysql_fetch_field似乎可以做你想要的。

mysql_fetch_field(0,0);

#2


Many wrapper libraries offer this, for example, with ADODb, it's simple

许多包装器库提供了这种功能,例如ADODb,它很简单

$value=$db->GetOne("select val from table where id=1");

It's not hard to roll your own either.

也不难推出自己的产品。

#3


You can use mysql_result() like this;

你可以像这样使用mysql_result();

mysql_result(mysql_query($query), 0, 0);

The second parameter selects the row, and the third is the field number.

第二个参数选择行,第三个参数是字段编号。