Php Mysql准备语句-选择
谁能给我一个建议?为什么查询不能为我提供一个期望值?谢谢Php Mysql准备语句-选择,php,mysql,prepare,Php,Mysql,Prepare,谁能给我一个建议?为什么查询不能为我提供一个期望值?谢谢 $mysqli = new mysqli($GLOBALS["mysql_host"], $GLOBALS["mysql_user"], $GLOBALS["mysql_passwd"], $GLOBALS["mysql_database"]); $stmt = $mysqli->prepare("SELECT one FROM table ORDER BY date DESC LIMIT 1"); $las
$mysqli = new mysqli($GLOBALS["mysql_host"], $GLOBALS["mysql_user"], $GLOBALS["mysql_passwd"], $GLOBALS["mysql_database"]);
$stmt = $mysqli->prepare("SELECT one FROM table ORDER BY date DESC LIMIT 1");
$last = $stmt->bind_result($one);
$stmt->execute();
$stmt->close();
$mysqli->close();
Echo $last; //it should be "abc"
我认为您必须执行
并在mysql\u stmt
-对象上调用fetch
。
因为您可能会得到多个结果(行)
使用fetch
您将推进结果光标
文件:
我可以。
一个简单明了的建议是:不要使用mysqli
改用
$stmt = $pdo->prepare("SELECT one FROM table ORDER BY date DESC LIMIT 1");
$stmt->execute();
$last = $stmt->fetchColumn();
echo $last; //it should be "abc"
干净、简单、有效MySQLi有什么问题吗?事实上,我也更喜欢PDO。它有一个很好的抽象层次。有一个问题你的问题是“谁能给我建议?”。好吧,只有了解你需要什么的人。为此,你的问题需要不那么含糊。
$stmt = $pdo->prepare("SELECT one FROM table ORDER BY date DESC LIMIT 1");
$stmt->execute();
$last = $stmt->fetchColumn();
echo $last; //it should be "abc"