dsfdsf48652 2014-05-14 13:45
浏览 45
已采纳

mysqli select不返回变量

I am trying to make a simple select query with mysqli but it seems like it does not work. Does anyone see what is wrong here? I expect the two variables being printed out at the end of the file.

$stmt = $mysqli->prepare("select billnumber, amount from bill where billid = ?");
$stmt->bind_param('i', $id);
$stmt->execute();
$stmt->bind_result($billnumber, $amount);
$stmt->fetch();

var_dump($mysqli);
echo "<br><br>";

var_dump($stmt);
echo "<br>";

echo $billnumber;
echo $amount;

$stmt->close();

Output:

object(mysqli)#2 (19) { ["affected_rows"]=> int(-1) ["client_info"]=> string(79) "mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $" ["client_version"]=> int(50011) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(2) ["host_info"]=> string(25) "Localhost via UNIX socket" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(6) "5.5.28" ["server_version"]=> int(50528) ["stat"]=> string(152) "Uptime: 2619401 Threads: 11 Questions: 220513466 Slow queries: 146 Opens: 14454832 Flush tables: 1 Open tables: 64 Queries per second avg: 84.184" ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(3244658) ["warning_count"]=> int(0) } 

object(mysqli_stmt)#4 (10) { ["affected_rows"]=> NULL ["insert_id"]=> NULL ["num_rows"]=> NULL ["param_count"]=> NULL ["field_count"]=> NULL ["errno"]=> NULL ["error"]=> NULL ["error_list"]=> NULL ["sqlstate"]=> NULL ["id"]=> NULL } 
  • 写回答

2条回答 默认 最新

  • doushui3061 2014-05-14 14:02
    关注

    mysqli_stmt_close()

    Closes a prepared statement. mysqli_stmt_close() also deallocates the statement handle. If the current statement has pending or unread results, this function cancels them so that the next query can be executed.

    You shouldn't close before your read the results

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)