Getting multiple rows with prepared statement

后端 未结 3 1736
梦毁少年i
梦毁少年i 2021-01-05 18:35

I\'m quite new to prepared statements and am not sure I am doing this right.

Here is what I try:

$currgame = 310791;

$sql = \"SELECT fk_player_id, p         


        
相关标签:
3条回答
  • 2021-01-05 18:52
    while (mysqli_stmt_fetch($stmt)) {
            printf ("%s (%s)\n", $name, $code);
        }
    

    This might help you:

    http://php.net/manual/en/mysqli-stmt.fetch.php

    0 讨论(0)
  • 2021-01-05 19:00

    Depending on your PHP/MySQL setup you may not be able to use get_result().

    The way to get around this is to bind the results.

    For example:

    $stmt->execute();
    
    $fk_player_id = null; $player_tiles = null; $player_draws = null; $player_turn = null; $player_passes = null; $swapped = null;
    
    $stmt->bind_result($fk_player_id, $player_tiles, $player_draws, $player_turn, $player_passes, $swapped);
    
    while ($stmt->fetch()) { // For each row
        /* You can then use the variables declared above, which will have the 
        new values from the query every time $stmt->execute() is ran.*/
    }
    

    For more information click here

    0 讨论(0)
  • 2021-01-05 19:04

    Since I don't see it in your code, make sure you're instantiating the mysqli object before trying to query on it:

    $mysqli = new mysqli("127.0.0.1", "user", "password", "mydb"); 
    if($mysqli->connect_error){
        die("$mysqli->connect_errno: $mysqli->connect_error");
    }
    

    Also, a ServerError would certainly show up in your logs and point you in the right direction.

    0 讨论(0)
提交回复
热议问题