开发者

Problem with Mysqli SELECT statement not returning anything

开发者 https://www.devze.com 2022-12-21 01:25 出处:网络
I\'m sure this will somebody no time at all. I know that MySqli works on this server as i have tried inserts and they work fine.

I'm sure this will somebody no time at all.

I know that MySqli works on this server as i have tried inserts and they work fine.

I also know that the information I'm trying to obtain is in the database and i can connect to the database without any problems. But I can't for the life of me figure out why this isn't working. I've tried both OO and Procedural but neither of them work. Can someone tell me what it is i'm supposed to be doing? Thanks

$table = 'newcms_broadcasting';

$sql = "SELECT first_info1 FROM $table WHERE region_id = ?";

echo $sql;

//echo $sql;


$region = '1';

$stmt = mysqli_prepare($connection, $sql);

    mysqli_stmt_bind_param("s", $region);
    mysqli_execute();
    mysqli_bind_result($result);

 开发者_Python百科   echo 'blah';

    // display the results
    mysqli_fetch($stmt);

    echo "name: $result";

    // clean up your mess!
    mysqli_close($stmt);


When using procedural style, you should pass $stmt into mysqli_stmt_bind_param, mysqli_stmt_execute, mysqli_bind_result etc

mysqli_stmt_bind_param($stmt, "s", $region);
mysqli_stmt_execute($stmt);
mysqli_bind_result($stmt, $result);
while (mysqli_stmt_fetch($stmt)) {
    print_r($result);
}


you forgot to include your compiled statement in binding results:

mysqli_stmt_bind_result($stmt, $result);

also note, that mysqli_fetch is deprecated, have you tried using a classic fetching while loop?

while (mysqli_stmt_fetch($stmt)) {
    print_r($result);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号