What's wrong with mysqli::get_result?

前端 未结 6 1959
情话喂你
情话喂你 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条回答
  •  萌比男神i
    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.

提交回复
热议问题