我有一个像这样的mysql表
name adults children
single 1 0
double 2 0
suite 3 0
但我无法使用此功能检索“成人”和“儿童”的值
function getInfo($mysqli, $c, $query){
// WARNING! THIS LINE IS NOT THE SQL QUERY BUT JUST AN ERROR LOG!
error_log("query is: SELECT " . $query . " FROM categories WHERE `name` = " . $c);
$mysqli->select_db("hotel");
$sql = $mysqli->prepare("SELECT ? FROM categories WHERE `name` = ?
LIMIT 0, 999999");
$sql->bind_param('ss', $query, $c);
$sql->bind_result($result);
while ($sql->fetch())
return($result);
}
错误日志显示变量已正确传递给函数:
[15-Apr-2013 19:36:10] SELECT adults FROM categories WHERE `name` = single
为什么这个函数返回NULL
?
答案 0 :(得分:1)
你错过了$sql->execute();
$sql->bind_param('ss', $query, $c);
$sql->execute();
$sql->bind_result($result);