<?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 name
");
$result = $sth->fetch(PDO::FETCH_ASSOC);
print_r($result);
print("
");
print("PDO::FETCH_BOTH: ");
print("Return next row as an array indexed by both column name and number
");
$result = $sth->fetch(PDO::FETCH_BOTH);
print_r($result);
print("
");
print("PDO::FETCH_LAZY: ");
print("Return next row as an anonymous object with column names as properties
");
$result = $sth->fetch(PDO::FETCH_LAZY);
print_r($result);
print("
");
print("PDO::FETCH_OBJ: ");
print("Return next row as an anonymous object with column names as properties
");
$result = $sth->fetch(PDO::FETCH_OBJ);
print $result->name;
print("
");
?>
$host = 'localhost'; // URL to the server
$username = 'root'; // Username (xampp = root)
$password = ''; // Password (xampp = )
$dbname = 'apifile';
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$sql = "SELECT * FROM `prop` WHERE propkey='localhost_100100'";
$q = $pdo->query($sql);
$q->setFetchMode(PDO::FETCH_ASSOC);
$r = $q->fetch();
var_dump($r['propvalue']);
$pdo = new PDO('mysql:host=$host; dbname=$database;', $user, $pass);
$stmt = $pdo->prepare('SELECT * FROM auction WHERE name = :name');
$stmt->bindParam(':name', $_GET['searchdivebay']);
$stmt->execute(array(':name' => $name);