Created
September 16, 2008 13:40
-
-
Save rafaelss/11035 to your computer and use it in GitHub Desktop.
Strange behavior of PDO::FETCH_CLASS fetch mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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