Answers for "pdo get data"

PHP
3

pdo fetch

<?php
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();

/* Exercise PDOStatement::fetch styles */
print("PDO::FETCH_ASSOC: ");
print("Return next row as an array indexed by column namen");
$result = $sth->fetch(PDO::FETCH_ASSOC);
print_r($result);
print("n");

print("PDO::FETCH_BOTH: ");
print("Return next row as an array indexed by both column name and numbern");
$result = $sth->fetch(PDO::FETCH_BOTH);
print_r($result);
print("n");

print("PDO::FETCH_LAZY: ");
print("Return next row as an anonymous object with column names as propertiesn");
$result = $sth->fetch(PDO::FETCH_LAZY);
print_r($result);
print("n");

print("PDO::FETCH_OBJ: ");
print("Return next row as an anonymous object with column names as propertiesn");
$result = $sth->fetch(PDO::FETCH_OBJ);
print $result->name;
print("n");
?>
Posted by: Guest on July-07-2020

Browse Popular Code Answers by Language