`
tw5566
  • 浏览: 447099 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

php中mysqli获取结果集

    博客分类:
  • php
 
阅读更多
$host = 'localhost'; 
$user = 'root'; 
$pass = 'root'; 
$data = 'test2'; 

$mysqli = new mysqli($host, $user, $pass, $data); 
/* check connection */ 
if (mysqli_connect_errno()) { 
    printf("Connect failed: %s\n", mysqli_connect_error()); 
    exit(); 
} 

if ($stmt = $mysqli->prepare("select * from user_info where name=?")) { 
    $tt2 = 'tw'; 
    
    $stmt->bind_param("s", $tt2); 
    $stmt->execute(); 

    $meta = $stmt->result_metadata(); 
    while ($field = $meta->fetch_field()) 
    { 
        $params[] = &$row[$field->name]; 
    } 

    call_user_func_array(array($stmt, 'bind_result'), $params); 

    while ($stmt->fetch()) { 
        foreach($row as $key => $val) 
        { 
            $c[$key] = $val; 
        } 
        $result[] = $c; 
    } 
    
    $stmt->close(); 
} 
$mysqli->close(); 
print_r($result);

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics