PHP: Mysqli prepared statement with “select *”

百般思念 提交于 2019-12-01 11:56:01

If you need to perform a selection of all of the columns:

SELECT * FROM `table`

You would use PHP's get_result() rather than bind_result().

bind_result() is better when you're specifying each column that you're retrieving where get_result() will allow you to work with a more generic return of data from your tables.

SELECT * is never a good idea.

It's better to be explicit.

If you had only 2 columns it would have worked.

That's how bind_result works the number variable needs to match the columns.

In addition to that it needs to be in the same order

Edit: Example in pdo:

if ($stmt = $pdo->prepare ("SELECT * from `$table_name` where cno >=:cno LIMIT 50" )){
    $stmt->execute([':cno'=>$cno]);
    $arrayUsers = $stmt->fetchAll();
    $stmt->close();
}
$pdo->close();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!