note 125973 added to pdo.query

From: Date: Wed, 31 Mar 2021 06:22:22 +0000
Subject: note 125973 added to pdo.query
Groups: php.notes 
Request: Send a blank email to php-notes+get-219298@lists.php.net to get a copy of this message
I would like to mention fetching rows from SQL query using PDO: <?php $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass); // use the connection here $sth = $dbh->query('SELECT * FROM countries'); // fetch all rows into array, by default PDO::FETCH_BOTH is used $rows = $stm->fetchAll(); // iterate over array by index and by name foreach($rows as $row) { printf("$row[0] $row[1] $row[2]\n"); printf("$row['id'] $row['name'] $row['population']\n"); } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 31.31.218.130) ---- Manual Page -- http://php.net/manual/en/pdo.query.php Edit -- https://master.php.net/note/edit/125973 Del: integrated -- https://master.php.net/note/delete/125973/integrated Del: useless -- https://master.php.net/note/delete/125973/useless Del: bad code -- https://master.php.net/note/delete/125973/bad+code Del: spam -- https://master.php.net/note/delete/125973/spam Del: non-english -- https://master.php.net/note/delete/125973/non-english Del: in docs -- https://master.php.net/note/delete/125973/in+docs Del: other reasons-- https://master.php.net/note/delete/125973 Reject -- https://master.php.net/note/reject/125973 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#219298) next »