note 107262 added to pdostatement.fetchall
| From: | Anonymous | Date: | Wed, 25 Jan 2012 20:04:39 +0000 |
| Subject: | note 107262 added to pdostatement.fetchall | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185743@lists.php.net to get a copy of this message | ||
Here's a sample of fetchAll() with the foreach-Loop and a predifined select-parameter.
This Code will display all data of books with the name "harry potter":
<?php
$seach_string = "harry potter";
try {
$database = new
PDO('mysql:host=localhost;dbname=book-db',"root","");
$stmt = $database->prepare('SELECT * FROM books WHERE name LIKE
"%":name"%"');
$stmt->bindParam(':name', $seach_string);
$stmt->execute();
$result = $stmt->fetchAll();
}
catch (PDOException $e)
{
echo "Error: ".$e->getMessage();
}
// List all Data from matched Book
foreach ($result as $value)
{
echo $value[0];
echo $value[1];
echo $value[2];
}
?>
----
Server IP: 212.124.37.9
Probable Submitter: 217.88.242.127
----
Manual Page -- http://www.php.net/manual/en/pdostatement.fetchall.php
Edit -- https://master.php.net/note/edit/107262
Del: integrated -- https://master.php.net/note/delete/107262/integrated
Del: useless -- https://master.php.net/note/delete/107262/useless
Del: bad code -- https://master.php.net/note/delete/107262/bad+code
Del: spam -- https://master.php.net/note/delete/107262/spam
Del: non-english -- https://master.php.net/note/delete/107262/non-english
Del: in docs -- https://master.php.net/note/delete/107262/in+docs
Del: other reasons-- https://master.php.net/note/delete/107262
Reject -- https://master.php.net/note/reject/107262
Search -- https://master.php.net/manage/user-notes.php