How do I loop through a MySQL query via PDO in PHP?

前端 未结 3 2069
执念已碎
执念已碎 2020-11-28 06:14

I\'m slowly moving all of my LAMP websites from mysql_ functions to PDO functions and I\'ve hit my first brick wall. I don\'t know ho

3条回答
  •  感动是毒
    2020-11-28 06:21

    According to the PHP documentation is says you should be able to to do the following:

    $sql = "SELECT * FROM widgets WHERE something='something else'";
    foreach ($database->query($sql) as $results)
    {
       echo $results["widget_name"];
    }
    

    I'm no expert, but this should work.

提交回复
热议问题