Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I recently switched to mysqli from mysql and started using prepared statements. in mysql we do

$result = mysql_query("SELECT * FROM table WHERE id = ?");

So we get the array of whole table in one variable.

But in mysqli we do

mysqli_stmt_bind_result($stmt, $result);

so basically here only one variable gets bind to variable result. How can we get the same variable(array) that we got from mysql?
PS - Hope my ques is clear enough. I know their are not many methods possible but i am luking for the best one.
PSS - I am more comfortable with the procedural way.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
423 views
Welcome To Ask or Share your Answers For Others

1 Answer

Finally this code is Working !!!!!

  <?php 
    $host = 'localhost'; 
    $user = 'root'; 
    $pass = '1234'; 
    $data = 'test'; 

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

    if ($stmt = $mysqli->prepare("SELECT * FROM sample WHERE t2 LIKE ?")) { 
        $tt2 = '%'; 

        $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); 
    ?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...