Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Mysql准备语句-选择_Php_Mysql_Prepare - Fatal编程技术网

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"