What's wrong with mysqli::get_result?

前端 未结 6 1942
情话喂你
情话喂你 2020-12-07 02:40

I have the following code:

$postId = $_GET[\'postId\'];
$mysqli = new mysqli(\'localhost\', \'username\', \'database\', \'name_db\');
mysqli_report(MYSQLI_RE         


        
相关标签:
6条回答
  • 2020-12-07 03:12

    check to see it your PHP mysql native driver is enable. get->result() only works when mysql native driver is enable. http://www.php.net/manual/en/mysqli-stmt.get-result.php

    0 讨论(0)
  • 2020-12-07 03:13

    As others have stated, it is only available in bleeding edge PHP. You could do something like this (answer to a similar question):

    function bind_array($stmt, &$row) {
        $md = $stmt->result_metadata();
        $params = array();
        while($field = $md->fetch_field()) {
            $params[] = &$row[$field->name];
        }
    
        call_user_func_array(array($stmt, 'bind_result'), $params);
    }
    
    // ....
    bind_array($stmt, $info);
    $stmt->fetch();
    
    echo json_encode($info);
    

    Or use mysqli::query if you have a simple query with no parameters - don't use it with dynamically generated SQL-statements.

    0 讨论(0)
  • 2020-12-07 03:14

    As mentioned in php documentation mysqli_stmt::get_result, this method is supported since PHP 5.3.0.

    And it is stated in the user notes section that:

    This method requires the mysqlnd driver. Othervise you will get this error: Call to undefined method mysqli_stmt::get_result()

    0 讨论(0)
  • 2020-12-07 03:25

    The manual page doesn't give any clear information on which minimum version of PHP is needed for get_result() to work:

    (No version information available, might only be in SVN)

    I don't know the background to this, but it may simply not be available in your PHP version.

    You could use fetch() instead.

    0 讨论(0)
  • 2020-12-07 03:25

    I´m guessing it´s the line below that, change:

    $info = $result->fecth_array(MYSQLI_ASSOC);
    

    to:

    $info = $result->fetch_array(MYSQLI_ASSOC);
    
    0 讨论(0)
  • 2020-12-07 03:32

    You're probably using old version of PHP not supporting get_result() as stated on manual page

    (No version information available, might only be in SVN)
    
    0 讨论(0)
提交回复
热议问题