How to SELECT * with multiple WHERE using fetch_assoc in prepared statements in PHP-MYSQL?

徘徊边缘 提交于 2019-12-24 10:23:09

问题


It's been two days and I have not found any solution for this on Google, so please help.

I have to SELECT * from one row with multiple WHERE clauses, using a prepared statements, I want to retrieve the results using fetch_assoc so that I don't have to bind variables using bind_result(), using fetch_assoc I can print many columns as $row['column_name']. My code is below and it's not running, giving no error.

$query = 'SELECT * FROM `table_name` WHERE `uid` = ? AND `email` = ?';

if ($stmt_select = $conn->prepare($query)) {
    $stmt_select->bind_param('is', $user_id, $user_email);

  $user_id = $_SESSION['uid']; //this variable is set and prints perfectly
  $user_email = $_SESSION['user_email']; //this variable is set and prints perfectly

    $result = $stmt_select->execute();

    $stmt_select->store_result();

    while ($row = $result->fetch_assoc()) {
        print_r($row);
        echo  $row["supermarket_name"];
        echo $row["supermarket-region"];
        /*Nothing is being printed*/
    }

    $stmt_select->free_result();

$stmt_select->close();

}else{
    echo 'query returned false';
}

The var_dump($result) returns (boolean)true

Since the above code isn't throwing any error and in last two days I couldn't figure out what's wrong with my code, can somebody let me know what's wrong with my code? Thanks!

来源:https://stackoverflow.com/questions/43862980/how-to-select-with-multiple-where-using-fetch-assoc-in-prepared-statements-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!