【问题标题】:Fatal error: Call to undefined method mysqli_result::execute()致命错误:调用未定义的方法 mysqli_result::execute()
【发布时间】:2014-02-02 15:31:52
【问题描述】:

所以这是目前令人头疼的代码。收到此错误:

致命错误:调用未定义的方法 mysqli_result::execute()

不知道我在哪里做错了:

$mysqli_load = new mysqli(HOST, USER, PASS, DB);
$query = 'SELECT `id`, `call_taker`, `call_time`, `call_type`, `call_priority`, `call_location`, `call_city`, `reporter_name`, `reporter_num`, `call_info` FROM `calls`';
$sql = mysqli_query($mysqli_load, $query) or die($mysqli_load->error);
$sql->execute() or die($mysqli_load->error);
$sql->bind_result($c_id, $c_taker, $c_time, $c_type, $c_priority, $c_location, $c_city, $r_name, $r_num, $c_info) or die($mysqli_load->error);
while($row = mysqli_fetch_assoc($sql)){

【问题讨论】:

    标签: php html mysqli


    【解决方案1】:

    mysqli_query 正在返回mysqli_result object,它具有用于操作查询结果的方法,例如 fetch、fetch_object 等,因为它是结果。此时已执行查询。

    mysqli::bind_result 的用法在错误的地方,应该在语句上运行。并且应该完全避免,因为它已在 PHP5.4 中删除。

    用这种方式来表达怎么样:

    $mysqli_load = new mysqli(HOST, USER, PASS, DB);
    $query = 'SELECT `id`, `call_taker`, `call_time`, `call_type`, `call_priority`, `call_location`, `call_city`, `reporter_name`, `reporter_num`, `call_info` FROM `calls`';
    $sql = mysqli_query($mysqli_load, $query) or die($mysqli_load->error);
    
    while ($row = mysqli_fetch_assoc($sql)) {
        // data manipulation
    }
    
    // and possibly close connection
    

    无需执行和绑定任何东西。

    为了将来参考,如果您的查询需要一些用户输入,请查看How can I prevent SQL injection in PHP?

    【讨论】:

      猜你喜欢
      • 2012-07-24
      • 2013-07-16
      • 2021-04-17
      • 1970-01-01
      • 2015-01-28
      • 2015-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多