php PDO fetchAll() - while not working, foreach works

后端 未结 5 1068
感动是毒
感动是毒 2020-12-11 16:37

I would like to know if i\'m doing fine OR fetchAll() doesn\'t work with WHILE.

here is an exemple

$db=new PDO(\"mysql:host=\" .$dbhost. \"; dbname=\         


        
5条回答
  •  再見小時候
    2020-12-11 17:26

    no need to loop through the recordset, because fetchAll - well - fetches all the records in one command. Nice, isn't it?

    $rows = $page->fetchAll(PDO::FETCH_ASSOC);
    
    // $rows is an array containing all records...
    foreach ($rows as $row)
        echo $row->fieldname;
    

提交回复
热议问题