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 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致