PHP MySQL:如何从预准备语句中获取结果?

时间:2015-10-25 13:01:52

标签: php mysql

table.resptable,
.resptable thead,
.resptable tbody,
.resptable th,
.resptable td,
.resptable tr

$conn = new mysqli(.....); $param = $_GET['manf']; $stmt = $conn->prepare('select manf from manf where manf = ?'); $stmt->bind_param('s', $param); $stmt->execute(); $stmt->store_result(); echo $stmt->num_rows; $result = $stmt->get_result(); if(!$result){ die(mysql_error()); } while($row = $result->fetch_assoc()){ echo $row['manf']; } 打印正确的vaule然而我无法从while语句中获得结果。我也试过echo $stmt->num_rows但是没有用 我怎样才能解决这个问题?

1 个答案:

答案 0 :(得分:1)

试试这个:

$conn = new mysqli(.....);
 $param = $_GET['manf'];

 $stmt = $conn->prepare('select manf from manf where manf = ?');
 $stmt->bind_param('s', $param);
 $stmt->execute();
 $stmt->bind_result($result);

 echo $stmt->num_rows;

 while($stmt->fetch()){
     echo $result;
 }
 $stmt->close();

要获取,您需要使用$stmt->fetch()

相关问题