Skip to content

Instantly share code, notes, and snippets.

@rafaelss
Created September 16, 2008 13:40
Show Gist options
  • Save rafaelss/11035 to your computer and use it in GitHub Desktop.
Save rafaelss/11035 to your computer and use it in GitHub Desktop.
Strange behavior of PDO::FETCH_CLASS fetch mode
<?php
class Project {
public function __construct() {
echo 'calling constructor', PHP_EOL;
}
public function __get($name) {
echo 'getting: ', $name, PHP_EOL;
}
public function __set($name, $value) {
echo 'setting: ', $name, ' with ', $value, PHP_EOL;
}
}
$db = new PDO('mysql:host=mysql;dbname=pdo_test', 'user', '****');
$stmt = $db->prepare('SELECT * FROM projects LIMIT 10');
$stmt->setFetchMode(PDO::FETCH_CLASS, 'Project');
$stmt->execute();
$projects = $stmt->fetchAll();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment