Up and running with doctrine 2 and zend framework 1

Post on 12-Jan-2015

4,299 views 4 download

Tags:

description

This speech has been delivered in phpXperts seminar 2010 at Brac University, Dhaka, Bangladesh

transcript

Up and running with Doctrine 2 and Zend Framework 1.10

DynamicGuy.com

@ferdous

github.com/dynamicguy

What is Doctrine?

Doctrine is a popular ORM for PHP which works with RDBMS via PHP objects. This is built inspired by Hibernate from JAVA. This acts as an abstraction layer between PHP and RDBMS.

Why should I use it?

- Because Nurul Ferdous said?

- Does it solve the world terrorism problem?

- No, don't be mad on me :) I am gonna explain it.

to SQL or NoSQL!

- MySQL

- Oracle

- PgSQL

- SQLite

- MsSQL

- IBMDB2

- etc

- MongoDB

- CouchDB

Inserting 20 records with Doctrine

Compare it to some raw PHP code

Insert performance

Doctrine 2 = 0.0094 seconds

mysql_query = 0.0165 seconds

Doctrine 2 is faster than raw PHP???

Why? The answer is transactions! Doctrine 2 manages our transactions for us and efficiently executes all inserts in a single, short transaction. The raw PHP code executes 1 transaction for each insert.

Here is the same raw PHP code with proper transaction usage

Insert performance

* Not trying to say Doctrine 2 is faster than raw PHP code

* Demonstrating that simple developer oversights and mis-use can cause the greatest performance problems

* This time around it only takes 0.0028 seconds compared to the previous 0.0165 seconds. Pretty cool, huh!

Where to start?

- http://doctrine-project.org/projects/orm/2.0/docs/en

- http://github.com/dynamicguy/zf1doctrine2

What we need?

- ZendX Doctrine2

- Individual Moduler setup (module wise db)

- Layout Switcher

File structure in library

File structure in Application

Working with code is often boring. Please don't sleep and bear with me

Configuration for blog module

A typical blog Entity in Doctrine 2

Generating schema from CLI

...blog/bin$ php doctrine orm:schema-tool:createCreating database schema...Database schema created successfully!.../blog/bin$

Fetch all records

Fetch one record

Adding new record

Deleting a record

Code thing is gone!You may wake up now!!

http://DynamicGuy.com

hello@dynamicguy.com