25
Up and running with Doctrine 2 and Zend Framework 1.10 DynamicGuy.com @ferdous github.com/dynamicguy

Up and running with doctrine 2 and zend framework 1

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Up and running with doctrine 2 and zend framework 1

Up and running with Doctrine 2 and Zend Framework 1.10

DynamicGuy.com

@ferdous

github.com/dynamicguy

Page 2: Up and running with doctrine 2 and zend framework 1

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.

Page 3: Up and running with doctrine 2 and zend framework 1

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.

Page 4: Up and running with doctrine 2 and zend framework 1

to SQL or NoSQL!

- MySQL

- Oracle

- PgSQL

- SQLite

- MsSQL

- IBMDB2

- etc

- MongoDB

- CouchDB

Page 5: Up and running with doctrine 2 and zend framework 1

Inserting 20 records with Doctrine

Page 6: Up and running with doctrine 2 and zend framework 1

Compare it to some raw PHP code

Page 7: Up and running with doctrine 2 and zend framework 1

Insert performance

Doctrine 2 = 0.0094 seconds

mysql_query = 0.0165 seconds

Page 8: Up and running with doctrine 2 and zend framework 1

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.

Page 9: Up and running with doctrine 2 and zend framework 1

Here is the same raw PHP code with proper transaction usage

Page 10: Up and running with doctrine 2 and zend framework 1

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!

Page 11: Up and running with doctrine 2 and zend framework 1

Where to start?

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

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

Page 12: Up and running with doctrine 2 and zend framework 1

What we need?

- ZendX Doctrine2

- Individual Moduler setup (module wise db)

- Layout Switcher

Page 13: Up and running with doctrine 2 and zend framework 1

File structure in library

Page 14: Up and running with doctrine 2 and zend framework 1

File structure in Application

Page 15: Up and running with doctrine 2 and zend framework 1

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

Page 16: Up and running with doctrine 2 and zend framework 1

Configuration for blog module

Page 17: Up and running with doctrine 2 and zend framework 1

A typical blog Entity in Doctrine 2

Page 18: Up and running with doctrine 2 and zend framework 1

Generating schema from CLI

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

Page 19: Up and running with doctrine 2 and zend framework 1

Fetch all records

Page 20: Up and running with doctrine 2 and zend framework 1

Fetch one record

Page 21: Up and running with doctrine 2 and zend framework 1

Adding new record

Page 22: Up and running with doctrine 2 and zend framework 1

Deleting a record

Page 23: Up and running with doctrine 2 and zend framework 1

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

Page 24: Up and running with doctrine 2 and zend framework 1
Page 25: Up and running with doctrine 2 and zend framework 1

http://DynamicGuy.com

[email protected]