mysqli->查询未返回任何内容 [英] mysqli->query not returning anything
问题描述
我在使用MySQLi时遇到麻烦.我已经习惯了旧的mysql_query,所以我确定这是一个非常愚蠢的问题. 我无法根据他们输入的电子邮件从数据库返回ID.
I'm having trouble with MySQLi. I am used to the old mysql_query, so I'm sure this is an incredibly stupid question. I am having trouble returning the ID from a database based on the email they entered.
这是查询代码:
$userid = $mysqli->query("SELECT id FROM client WHERE email = $email");
回显$ userid不会返回任何内容.
Echoing $userid does not return anything.
我是MySQLi的新手,所以这可能很简单.
I am new to MySQLi, so this is probably something very simple.
谢谢.
推荐答案
mysqli: :query :
返回值
失败时返回FALSE.对于成功的SELECT,SHOW,DESCRIBE或EXPLAIN查询,mysqli_query()将返回mysqli_result对象.对于其他成功的查询,mysqli_query()将返回TRUE.
Return Values
Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.
因此结果应为TRUE
,FALSE
或 mysqli_result对象,而不是您期望的查询的实际结果.
So the result should be TRUE
, FALSE
or a mysqli_result object, not the actual result of the query like you're expecting.
您需要执行以下操作:
$result = $mysqli->query("SELECT id FROM client WHERE email = $email");
if($result === FALSE) {
die("Uh oh something went wrong");
}
然后使用类似 mysqli_result::fetch_array()
之类的东西.
Then use something like mysqli_result::fetch_array()
.
这篇关于mysqli->查询未返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!