php – MYSQLi bind_result返回null

前端之家收集整理的这篇文章主要介绍了php – MYSQLi bind_result返回null前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图输出我在查询中从数据库获取的变量,但没有返回任何内容.使用MysqLi编写的语句.

请参阅以下代码

  1. $stmt = $con->prepare("SELECT first_name,last_name FROM transactions WHERE order_id = ?");
  2. $stmt->bind_param('i',$order_id);
  3. $stmt->execute();
  4. $stmt->store_result();
  5. $stmt->bind_result($first_name,$last_name);
  6. $stmt->close();
  7.  
  8.  
  9. // Output review live to page
  10. echo $first_name;

我看不出我错在哪里? PS我是准备好的陈述的新手,所以请放轻松我吧!

你忘记了获取结果的行. fetch().

试试看:

  1. $stmt->bind_result($first_name,$last_name);
  2. $stmt->fetch(); // ----- > you forget that line to fetch results.
  3. $stmt->close();

猜你在找的PHP相关文章