Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Student {
- public $id;
- public $first_name;
- public $last_name
- public function getFullName() {
- return $this->first_name.' '.$this->last_name
- }
- }
- try
- {
- $dbh = new PDO("mysql:host=$hostname;dbname=school", $username, $password)
- $stmt = $dbh->query("SELECT * FROM students");
- /* MAGIC HAPPENS HERE */
- $stmt->setFetchMode(PDO::FETCH_INTO, new Student);
- foreach($stmt as $student)
- {
- echo $student->getFullName().'<br />';
- }
- $dbh = null;
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- }
- //Dit is het grote nut van PDO..
Add Comment
Please, Sign In to add comment