rafaelss (owner)

Revisions

gist: 11035 Download_button fork
public
Description:
Strange behavior of PDO::FETCH_CLASS fetch mode
Public Clone URL: git://gist.github.com/11035.git
Embed All Files: show embed
PHP #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?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();
?>