Doctrine – ORM for PHP. Doctrine ● ORM dla PHP oparty na abstrakcyjnej warstwie dostępu do bazy danych (DBAL) ● Zapytania w postaci DQL wzorowanym.

1 Doctrine – ORM for PHP ...
Author: Henryk Wróbel
0 downloads 0 Views

1 Doctrine – ORM for PHP

2 Doctrine ● ORM dla PHP 5.2.3+ oparty na abstrakcyjnej warstwie dostępu do bazy danych (DBAL) ● Zapytania w postaci DQL wzorowanym na HQL

3 Doctrine przykład(1) SELECT u.id AS u__id, u.is_active AS u__is_active, u.is_super_admin AS u__is_super_admin, u.first_name AS u__first_name, u.last_name AS u__last_name, u.username AS u__username, u.password AS u__password, u.type AS u__type, u.created_at AS u__created_at, u.updated_at AS u__updated_at, p.id AS p__id, p.user_id AS p__user_id, p.phonenumber AS p__phonenumber FROM user u LEFT JOIN phonenumber p ON u.id = p.user_id

4 Doctrine – przykład (2) $users = Doctrine_Core::getTable('User')->findAll(); foreach($users as $user) { echo $user->username. " has phonenumbers: \n"; foreach($user->Phonenumbers as $phonenumber) { echo $phonenumber->phonenumber. "\n"; }

5 Doctrine – przykład (3) $q = Doctrine_Query::create() ->from('User u') ->leftJoin('u.Phonenumbers p') ; $users = $q->execute(); foreach($users as $user) { echo $user->username. " has phonenumbers: \n"; foreach($user->Phonenumbers as $phonenumber) { echo $phonenumber->phonenumber. "\n"; }

6 Doctrine - cd ● $q = Doctrine_Core::getTable('Comment') ● ->createQuery('c') ● ->where('c.author = ?', 'Steve') ● ->leftJoin('c.Article a') ● ->andWhere('a.content LIKE ?', '%enjoy%') ● ->orderBy('c.created_at ASC'); ● $comments = $q->execute();

7 Doctrine - Symfony (databases.yml) all: doctrine: class: sfDoctrineDatabase param: dsn: mysql://login:passwd@localhost/blog php symfony doctrine:build-model php symfony doctrine:build-sql php symfony doctrine:build-schema – generowanie yml z istniejącej bazy Więcej informacji na: http://www.symfony-project.org/gentle-introduction/1_4/en/08-Inside-the-Model-Layer-Doctrine