How can I put the results of a MySQLi prepared statement into an associative array?

后端 未结 7 1497
清酒与你
清酒与你 2020-12-01 09:54

I have a sql query and a mysqli prepared statement:

$sql = \'SELECT photographers.photographer_id, photographers.photographer_name
    FROM photographers\';
         


        
7条回答
  •  囚心锁ツ
    2020-12-01 10:44

    A simple one that actually surprisingly works. I know it's procedural, but still:

    $query = "SELECT * FROM foo WHERE bar = ?;";
    
    $stmt = mysqli_prepare($dbc, $query);
    
    mysqli_stmt_bind_param($stmt, "s", $bar);
    
    mysqli_stmt_execute($stmt);
    
    $result = mysqli_stmt_get_result($stmt);
    
    return mysqli_fetch_assoc($result);
    

提交回复
热议问题