SlideShare ist ein Scribd-Unternehmen logo
1 von 54
Downloaden Sie, um offline zu lesen
Zend Framework
Database Quick Start
Bill Karwin
Product Engineering Manager,
Zend Framework
Introduction


 • What’s in the Zend_Db component?
 • Examples of using each class
 • Using Zend_Db in MVC applications




   2007-10-09           Zend Framework Database Quick Start PAGE 2
What is the Zend Framework?

 •   PHP class library      • Provides common web
                              application functionality –
 •   Open source              so you don’t have to
 •   Emphasis on quality    • Use-at-will library of
 •   “Extreme simplicity”     object-oriented PHP
                              classes
 •   Popular                • 154,000+ lines of code
                            • 100% PHP – works on
                              standard PHP as well as
                              Zend Core
                            • Requires PHP 5.1.4+




     2007-10-09                     Zend Framework Database Quick Start PAGE 3
What is the Zend Framework?

 •   PHP class library      • Free software for
                              development and
 •   Open source              deployment
 •   Emphasis on quality    • New BSD license
 •   “Extreme simplicity”     (similar to PHP itself)
                            • Friendly to commercial
 •   Popular                  projects
                            • Code is free of legal
                              claims, by virtue of the
                              Contributor License
                              Agreement




     2007-10-09                     Zend Framework Database Quick Start PAGE 4
What is the Zend Framework?

 •   PHP class library      • Agile development model
 •   Open source            • Frequent evaluation by
                              large user community
 •   Emphasis on quality    • Goal of 90% coverage in
 •   “Extreme simplicity”     automated tests
 •   Popular                • Tests consist of 105,000+
                              lines of code (40% of total
                              code)
                            • Thorough documentation




     2007-10-09                     Zend Framework Database Quick Start PAGE 5
What is the Zend Framework?

 •   PHP class library      • Designed to make
                              development easy
 •   Open source
                            • Solves 80% most needed
 •   Emphasis on quality      use cases
 •   “Extreme simplicity”   • Extensible; developers
                              implement custom
 •   Popular                  behavior from the
                              remaining 20% (think of
                              the “long tail”)




     2007-10-09                    Zend Framework Database Quick Start PAGE 6
What is the Zend Framework?

 •   PHP class library      • Over 2.2 M downloads –
                              increasing!
 •   Open source
                            • Over 300 contributors
 •   Emphasis on quality    • Powers some high-profile
 •   “Extreme simplicity”     web sites
                                 IBM QEDWiki
 •   Popular
                                 Right Media Advertising
                                 Exchange
                                 Varien Magento
                                 bwin International
                                 In-Ticketing
                                 fav.or.it




     2007-10-09                    Zend Framework Database Quick Start PAGE 7
What’s in the Zend_Db component?

 • Database Adapters        • Common interface to
                              multiple databases
 • CRUD functions           • Supports both PDO and
 • Quoting SQL                native database extensions:
                                  Mysqli
   identifiers and values
                                  Oracle OCI8
 • Query Profiler                 IBM DB2
                                  PDO IBM
 • Query builder
                                  PDO Mysql
 • Table and Row                  PDO Mssql
   OO patterns                    PDO OCI
                                  PDO Pgsql
                                  PDO Sqlite




   2007-10-09                       Zend Framework Database Quick Start PAGE 8
What’s in the Zend_Db component?

 • Database Adapters        Basic database operations
 • CRUD functions           • insert()
                            • update()
 • Quoting SQL
                            • delete()
   identifiers and values
                            • query()
 • Query Profiler           • fetchAll()
 • Query builder            • etc.
 • Table and Row
   OO patterns




   2007-10-09                      Zend Framework Database Quick Start PAGE 9
What’s in the Zend_Db component?

 • Database Adapters    • Encourages safer
                          interpolation of values into
 • CRUD functions         SQL strings
 • Quoting SQL values   • Both values and SQL
   and identifiers        identifiers are supported
 • Query Profiler       • Not the same thing as SQL
                          parameters – but those
 • Query builder          are supported too
 • Table and Row        • Both quoting and SQL
   OO patterns            parameters help you to
                          defend against SQL
                          injection issues



   2007-10-09                   Zend Framework Database Quick Start PAGE 10
What’s in the Zend_Db component?

 • Database Adapters        • Measures duration of SQL
                              queries
 • CRUD functions
                            • Filters by SQL statement
 • Quoting SQL                type or by minimum
   identifiers and values     duration
 • Query profiler           • Reports recorded SQL
                              statements and bound
 • Query builder              parameter values
 • Table and Row
   OO patterns




   2007-10-09                      Zend Framework Database Quick Start PAGE 11
What’s in the Zend_Db component?

 • Database Adapters        • Procedural interface to
                              create SELECT queries
 • CRUD functions
                            • Convenient when you
 • Quoting SQL                need to “build” SQL with
   identifiers and values     application logic
 • Query Profiler           • Helps you to produce
                              valid SQL SELECT syntax
 • Query builder
 • Table and Row
   OO patterns




   2007-10-09                      Zend Framework Database Quick Start PAGE 12
What’s in the Zend_Db component?

 • Database Adapters        • Similar to ActiveRecord
                              pattern in other
 • CRUD functions             frameworks
 • Quoting SQL              • Flexible and extensible
   identifiers and values     base classes for Tables,
                              Rowsets, and Rows
 • Query Profiler
                            • Emphasis on supporting
 • Query builder              existing database
 • Table and Row              schema; no restrictive
   OO patterns                conventions
                            • Often used in Model
                              classes in MVC apps



   2007-10-09                       Zend Framework Database Quick Start PAGE 13
Database Adapters




2007-10-09       Zend Framework Database Quick Start PAGE 14
Connecting to a database

 • Use the static factory() method of Zend_Db:
        require_once ‘Zend/Db.php’;
        $db = Zend_Db::factory(‘Mysqli’,
         array(
             ‘host’    => ’localhost’,
             ‘dbname’ => ’test’,
             ‘username’=> ’webappuser’,
             ‘password’=> ’xxxxxxxx’)
          );

 • Returns an object of Zend_Db_Adapter_Mysqli,
   which extends Zend_Db_Adapter_Abstract


   2007-10-09                              Zend Framework Database Quick Start PAGE 15
Running an SQL query and fetching results

 • Use the fetchAll() method to return an array of
   rows. Each row is an associative array:

        $data = $db->fetchAll(‘SELECT * FROM bugs’);
        foreach ($data as $row) {
          echo $row[‘bug_description’];
        }


 • You can fetch rows one-by-one in a loop
 • You can fetch rows as other structures



   2007-10-09                            Zend Framework Database Quick Start PAGE 16
Preparing an SQL query

 • Use the prepare() or query() methods to create
   a Statement object:
        $stmt = $db->prepare(
         ‘SELECT * FROM bugs
         WHERE bug_status = ?’);
 • Execute once, giving a parameter value:
        $stmt->execute(array(‘OPEN’));
        $openBugs = $stmt->fetchAll();
 • Execute a second time, giving another value:
        $stmt->execute(array(‘CLOSED’));
        $closedBugs = $stmt->fetchAll();



   2007-10-09                              Zend Framework Database Quick Start PAGE 17
Inserting data

 • Use the insert() method.
 • Pass the table name, and an associative array
   mapping columns to values:
        $db->insert( ‘bugs’,
           array(
               ‘bug_description’ => ‘help me’,
               ‘bug_status’      => ‘NEW’)
        );
 • Get an auto primary key value (if applicable):
        $bugId = $db->lastInsertId();




   2007-10-09                              Zend Framework Database Quick Start PAGE 18
Updating data

 • Use the update() method.
 • Pass the table name, an associative array
   mapping columns to new values, and an
   expression for the WHERE clause:

        $n = $db->update( ‘bugs’,
           array(‘bug_status’ => ‘NEW’),
           ‘bug_id = 123’
        );


 • Returns the number of rows affected.


   2007-10-09                              Zend Framework Database Quick Start PAGE 19
Deleting data

 • Use the delete() method.
 • Pass the table name, and
   an expression for the WHERE clause:

        $n = $db->delete(‘bugs’, ‘bug_id = 321’);


 • Returns the number of rows affected.




   2007-10-09                             Zend Framework Database Quick Start PAGE 20
Retrieving table metadata

 • Use the describeTable() method:
        $bugsMetadata = $db->describeTable(‘bugs’);
 • Returns an array indexed by column name:
        array(
          ‘bug_id’            => array(…),
          ‘bug_description’   => array(…),
          ‘bug_status’        => array(…),
          ‘created_on’        => array(…),
          ‘updated_on’        => array(…),
          ‘reported_by’       => array(…),
          ‘assigned_to’       => array(…),
          ‘verified_by’       => array(…),
        )



   2007-10-09                                Zend Framework Database Quick Start PAGE 21
Retrieving table metadata

 • Each value is an associative array of metadata
   for the respective column:
            ‘bug_id’ => array(
               ‘TABLE_NAME’               => ‘bugs’
               ‘COLUMN_NAME’              => ‘bug_id’
               ‘COLUMN_POSITION’          => 1
               ‘DATA_TYPE’                => ‘INTEGER’
               ‘DEFAULT’                  => null
               ‘NULLABLE’                 => false
               ‘LENGTH’                   => null
               ‘SCALE’                    => null
               ‘PRECISION’                => null
               ‘UNSIGNED’                 => null
               ‘PRIMARY’                  => true
               ‘PRIMARY_POSITION’         => 1
               ‘IDENTITY’                 => true
          ),
          …entries for other columns follow…



   2007-10-09                                  Zend Framework Database Quick Start PAGE 22
Quoting SQL




2007-10-09            Zend Framework Database Quick Start PAGE 23
Quoting SQL


 • Important when interpolating strings and
   PHP variables into SQL
 • Not the same thing as query parameters
        Interpolated values add to a SQL query
        before prepare-time
        Query parameters supply values to a
        prepared query at execute-time




   2007-10-09                      Zend Framework Database Quick Start PAGE 24
Quoting SQL values


 • Use the quote() method to turn a string or
   variable into a quoted SQL string:
        $expr = $db->quote(“O’Reilly”);
        $stmt = $db->query(“SELECT * FROM bugs
         WHERE bug_reporter = $expr”);

   note: unlike mysql_real_escape_string(),
   the quote() method returns a string with quotes.
        mysql_real_escape_string(“O’Reilly”) returns:             O’Reilly
        $db->quote(“O’Reilly”) returns:                           ‘O’Reilly’




   2007-10-09                                  Zend Framework Database Quick Start PAGE 25
Quoting SQL values in expressions

 • Use the quoteInto() method to substitute a scalar
   into a SQL expression:

        $whereExpr = $db->quoteInto(‘bug_reporter = ?’,
         “O’Reilly”);
        $stmt = $db->query(
         “SELECT * FROM bugs WHERE $whereExpr”);


 • Results in the following query:
        SELECT * FROM bugs WHERE bug_reporter = ‘O’Reilly’




   2007-10-09                           Zend Framework Database Quick Start PAGE 26
Quoting SQL identifiers

 • Identifiers are table names, column names, etc.
 • Use the quoteIdentifier() method :
        $table = $db->quoteIdentifier(‘My Table’);
        $stmt = $db->query(“SELECT * FROM $table WHERE …”);

 • Results in the following query:
        SELECT * FROM “My Table” WHERE …

 • Helps if your identifiers contain whitespace,
   international characters, SQL keywords, etc.



   2007-10-09                          Zend Framework Database Quick Start PAGE 27
Query Profiler




2007-10-09              Zend Framework Database Quick Start PAGE 28
Profiling SQL queries

 • Measures time to execute SQL queries

 • Useful during development/debugging

 • The Adapter has a Zend_Db_Profiler object,
   which is disabled by default
        $db->getProfiler()->setEnabled(true);


 • While the profiler is enabled, SQL queries are
   recorded, with the time it takes them to run.


   2007-10-09                             Zend Framework Database Quick Start PAGE 29
Profiling SQL queries: find longest query

        $prof = $db->getProfiler();
        $prof->setEnabled(true);

        // run one or more queries with profiler enabled
        $db->query(…); $db->insert(…); $db->update(…);

        $max = 0;
        foreach ($prof->getQueryProfiles() as $q) {
          if ($q->getElapsedSecs() > $max) {
               $max = $q->getElapsedSecs();
               $longestQuery = $q->getQuery();
          }
        }
        echo “The longest query ran $max secondsn”;
        echo “SQL = $longestQueryn”;

   2007-10-09                           Zend Framework Database Quick Start PAGE 30
Profiling SQL queries: filtering

 • Filtering queries to be recorded
         // By minimum duration:
         $prof->setFilterElapsedSecs(5);

         // By query type:
         $prof->setFilterQueryType(Zend_Db_Profiler::SELECT
               | Zend_Db_Profiler::UPDATE);


 • Filtering queries to be reported
         $prof->getQueryProfiles(Zend_Db_Profiler::SELECT);




    2007-10-09                             Zend Framework Database Quick Start PAGE 31
Query Builder




2007-10-09             Zend Framework Database Quick Start PAGE 32
Building a SELECT query

 • Use the select() method of the Adapter to get
   an object of Zend_Db_Select:

        $select = $db->select();
        $select->from(‘bugs’);
        $select->where(‘bug_status = ?’, ‘NEW’);


 • Execute the query using the Zend_Db_Select
   object instead of a SQL string:
        $data = $db->fetchAll($select);




   2007-10-09                             Zend Framework Database Quick Start PAGE 33
Building a SELECT query

 • The fluent usage can be convenient:
        $select = $db->select()->from(‘bugs’)
             ->where(‘bug_status = ?’, ‘NEW’);

 • You can mix fluent and traditional usage.
 • You can add SQL clauses in any order.
        $select = $db->select()->from(‘bugs’)->order(‘bug_id’);
        if ($condition == true) {
              $select->joinNatural(‘other_table’);
        }




   2007-10-09                             Zend Framework Database Quick Start PAGE 34
Building a SELECT query: other SQL clauses

• Additional functions:        $select = $db->select()
     DISTINCT modifier         ->distinct()
     Specify columns
                               ->from(array(‘a’=>‘accounts’),
     Table correlation names
                                   array(‘account_name’,
     Specify SQL expressions            ‘num_bugs’=>‘COUNT(*)’))
     Column aliases
                               ->joinLeft(array(‘b’=>‘bugs’),
     Joins to other tables         ‘b.reported_by =
     GROUP BY clause                a.account_name’)
     HAVING clause             ->group(‘a.account_name’)
     ORDER BY clause
                               ->having(‘num_bugs < 5’)
     LIMIT clause
                               ->order(‘a.account_name ASC’)
                               ->limit(10, 20);


      2007-10-09                         Zend Framework Database Quick Start PAGE 35
Table and Row
             Object-Oriented
                 Patterns


2007-10-09             Zend Framework Database Quick Start PAGE 36
Table Data Gateway

 • Like the ActiveRecord pattern, this provides a
   simple OO interface for a database table.
 • Table Data Gateway and Row Data Gateway
   patterns are based on Martin Fowler’s “Patterns
   of Enterprise Architecture.”
 • Base classes for Table, Row, and Rowset are
   extensible, to allow you to define business logic.
 • You may use Table objects in your MVC Model
   classes, or as your MVC Models.




   2007-10-09                       Zend Framework Database Quick Start PAGE 37
Table Data Gateway: define a table

 • Start by defining a class for each table:

        class Bugs extends Zend_Db_Table_Abstract
        {
          protected $_name = ‘bugs’;
        }

 • Default code is inherited from the base
   Zend_Db_Table_Abstract class.
 • You don’t need to define $_name if the class
   name matches the name of the table in the
   database.


   2007-10-09                           Zend Framework Database Quick Start PAGE 38
Table Data Gateway: instantiate a table

 • Option #1: pass the database Adapter object to
   the Table constructor:
        $bugsTable = new Bugs( $db );


 • Option #2: set a default Adapter for all Tables:
        Zend_Db_Table_Abstract::setDefaultAdapter($db);
        $bugsTable = new Bugs();

 • Option #3: save the Adapter object in
   Zend_Registry and reference it later by key:
        Zend_Registry::set(‘myDb’, $db);
        $bugsTable = new Bugs( ‘myDb’ );


   2007-10-09                              Zend Framework Database Quick Start PAGE 39
Table Data Gateway: query a table

 • Use the fetchAll() method to get a Rowset with
   all rows matching a condition you specify:
        $rowset = $bugsTable->fetchAll(“bug_status = ‘OPEN’”);


 • A Rowset object is iterable and countable.
 • A Rowset is a collection of Row objects.
 • A Row has an accessor for each column.
        foreach ($rowset as $row) {
          echo “$row->bug_id: $row->bug_descriptionn”;
        }



   2007-10-09                            Zend Framework Database Quick Start PAGE 40
Table Data Gateway: find by primary key

 • Use the find() method with a primary key value
   or an array of values:

        $bugsTable = new Bugs();
        $rowset1 = $bugsTable->find(123);
        $rowset2 = $bugsTable->find( array(123, 321) );


 • $rowset1 contains 0 or 1 Row
 • $rowset2 contains up to 2 Rows




   2007-10-09                              Zend Framework Database Quick Start PAGE 41
Table Data Gateway: UPDATE

 • Get the Row you want to update:
        $bugsTable = new Bugs();
        $rowset = $bugsTable->find(123);
        $row = $rowset->current();

 • Set a column value using the accessor:
        $row->bug_description = ‘New description’;

 • Use the save() method of the Row object to post
   the change to the database:
        $row->save();



   2007-10-09                              Zend Framework Database Quick Start PAGE 42
Table Data Gateway: INSERT

 • Use the createRow() method of the Table object
   to get a blank Row:
        $bugsTable = new Bugs();
        $newRow = $bugsTable->createRow();

 • Set Row fields:
        $newRow->bug_description = ‘help me’;
        $newRow->bug_status = ‘NEW’;

 • Use the save() method of new Row object to
   post it to the database:
        $newRow->save();


   2007-10-09                          Zend Framework Database Quick Start PAGE 43
Table Data Gateway: DELETE

 • Get a Row you want to delete:
        $bugsTable = new Bugs();
        $row = $bugsTable->find(123)->current();

 • Use the delete() method of the Row object:
        $row->delete();




   2007-10-09                             Zend Framework Database Quick Start PAGE 44
Table Data Gateway: relationships

 • Assume an Entity-Relationship like this:

                  reported by
        bugs                     accounts



 • Get a Row from the Accounts table:
        $accountsTable = new Accounts();
        $account = $accountsTable->find(‘bill’)->current();
 • Find a Rowset in related table Bugs:
        $reportedBugs = $account->findBugs();



   2007-10-09                               Zend Framework Database Quick Start PAGE 45
Table Data Gateway: relationships

 • You also can get the parent row. Start with the
   dependent row in Bugs:
        $bugsTable = new Bugs();
        $bug = $bugsTable->find(123)->current();

 • Find the parent Row in related table Accounts:
        $reporter = $bug->findParentAccounts();




   2007-10-09                            Zend Framework Database Quick Start PAGE 46
Table Data Gateway: relationships

 • Declare table relationships in the table class:
       class Accounts extends Zend_Db_Table_Abstract
       {
             protected $_name = ‘accounts’;
       }
       class Bugs extends Zend_Db_Table_Abstract
       {
             protected $_name = ‘bugs’;
       }     protected $_referenceMap = array(
                 ‘Reporter’ => array(
                     ‘columns’        => array(‘reported_by’),
                     ‘refTableClass’ => ‘Accounts’
                 ));
        }
   2007-10-09                             Zend Framework Database Quick Start PAGE 47
Table Data Gateway: customization

 • You can add custom logic to a Table class:
       class Bugs extends Zend_Db_Table_Abstract
       {
             protected $_name = ‘bugs’;

                public function insert(array $data)
                {
                  if (empty($data['created_on'])) {
                        $data['created_on'] = time();
                  }
                  return parent::insert($data);
                }
       }


   2007-10-09                                Zend Framework Database Quick Start PAGE 48
Using Zend_Db in
             MVC Applications



2007-10-09              Zend Framework Database Quick Start PAGE 49
Using Zend_Db in MVC Applications

 • Each Model class in the MVC architecture
   encapsulates data and operations on data for a
   logical domain within your application.
 • You can use either Zend_Db_Table objects or
   direct SQL queries to implement persistence for
   Model data.
 • Common to define Models using an “is-a”
   relationship to Zend_Db_Table, but it can be
   more flexible to use a “has-a” relationship
   instead.



   2007-10-09                    Zend Framework Database Quick Start PAGE 50
Using Zend_Db in MVC Applications

 • Simple Models can extend directly from
   Zend_Db_Table_Abstract:

        class Countries extends Zend_Db_Table_Abstract
        {
          protected $_name = ‘countries’;
        }

 • Good if this Model corresponds one-to-one with
   a single physical database table.




   2007-10-09                           Zend Framework Database Quick Start PAGE 51
Using Zend_Db in MVC Applications

 • More complex Models use multiple Tables, or
   else Db Adapter methods to execute SQL.

        class QuarterlyReport // extends nothing
        {
          protected $_salesTable;
          protected $_productsTable;
          protected $_dbAdapter; // for direct SQL queries
          public function getReport($quarter) { … }
        }

 • Good if you want this Model’s interface to be
   decoupled from the physical database
   structure.

   2007-10-09                             Zend Framework Database Quick Start PAGE 52
Recap of Zend_Db


 •   Adapters to PHP database extensions
 •   Quoting SQL identifiers and values
 •   Query profiler
 •   SELECT query builder
 •   Table Data Gateway &
     Row Data Gateway




     2007-10-09               Zend Framework Database Quick Start PAGE 53
Thanks
http://framework.zend.com/

Weitere ähnliche Inhalte

Was ist angesagt?

Java Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief OverviewJava Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief OverviewCraig Dickson
 
PHP on IBM i Tutorial
PHP on IBM i TutorialPHP on IBM i Tutorial
PHP on IBM i TutorialZendCon
 
JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6Bert Ertman
 
Django è pronto per l'Enterprise
Django è pronto per l'EnterpriseDjango è pronto per l'Enterprise
Django è pronto per l'EnterprisePyCon Italia
 
Hibernate in XPages
Hibernate in XPagesHibernate in XPages
Hibernate in XPagesToby Samples
 
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your ApplicationsThe Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your Applicationsbalassaitis
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologySimon Ritter
 
PHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM iPHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden
 
XPages and Java (DanNotes 50th conference, November 2013)
XPages and Java (DanNotes 50th conference, November 2013)XPages and Java (DanNotes 50th conference, November 2013)
XPages and Java (DanNotes 50th conference, November 2013)Per Henrik Lausten
 
JavaScript Interview Questions and Answers | Full Stack Web Development Train...
JavaScript Interview Questions and Answers | Full Stack Web Development Train...JavaScript Interview Questions and Answers | Full Stack Web Development Train...
JavaScript Interview Questions and Answers | Full Stack Web Development Train...Edureka!
 
Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)Hamed Hatami
 
Web services on IBM i with PHP and Zend Framework
Web services on IBM i with PHP and Zend FrameworkWeb services on IBM i with PHP and Zend Framework
Web services on IBM i with PHP and Zend FrameworkAlan Seiden
 
Developing Enterprise Applications Using Java Technology
Developing Enterprise Applications Using Java TechnologyDeveloping Enterprise Applications Using Java Technology
Developing Enterprise Applications Using Java TechnologySimon Ritter
 
Zend Products and PHP for IBMi
Zend Products and PHP for IBMi  Zend Products and PHP for IBMi
Zend Products and PHP for IBMi Shlomo Vanunu
 
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Reviewnetc2012
 
Lessons from a Dying CMS
Lessons from a Dying CMSLessons from a Dying CMS
Lessons from a Dying CMSSandy Smith
 

Was ist angesagt? (20)

Java Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief OverviewJava Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief Overview
 
PHP on IBM i Tutorial
PHP on IBM i TutorialPHP on IBM i Tutorial
PHP on IBM i Tutorial
 
JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6
 
Django è pronto per l'Enterprise
Django è pronto per l'EnterpriseDjango è pronto per l'Enterprise
Django è pronto per l'Enterprise
 
Hybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbaiHybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbai
 
Hibernate in XPages
Hibernate in XPagesHibernate in XPages
Hibernate in XPages
 
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your ApplicationsThe Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
 
Wt unit 1 ppts web development process
Wt unit 1 ppts web development processWt unit 1 ppts web development process
Wt unit 1 ppts web development process
 
Net framework
Net frameworkNet framework
Net framework
 
PHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM iPHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM i
 
Asif
AsifAsif
Asif
 
XPages and Java (DanNotes 50th conference, November 2013)
XPages and Java (DanNotes 50th conference, November 2013)XPages and Java (DanNotes 50th conference, November 2013)
XPages and Java (DanNotes 50th conference, November 2013)
 
JavaScript Interview Questions and Answers | Full Stack Web Development Train...
JavaScript Interview Questions and Answers | Full Stack Web Development Train...JavaScript Interview Questions and Answers | Full Stack Web Development Train...
JavaScript Interview Questions and Answers | Full Stack Web Development Train...
 
Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)
 
Web services on IBM i with PHP and Zend Framework
Web services on IBM i with PHP and Zend FrameworkWeb services on IBM i with PHP and Zend Framework
Web services on IBM i with PHP and Zend Framework
 
Developing Enterprise Applications Using Java Technology
Developing Enterprise Applications Using Java TechnologyDeveloping Enterprise Applications Using Java Technology
Developing Enterprise Applications Using Java Technology
 
Zend Products and PHP for IBMi
Zend Products and PHP for IBMi  Zend Products and PHP for IBMi
Zend Products and PHP for IBMi
 
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Review
 
Lessons from a Dying CMS
Lessons from a Dying CMSLessons from a Dying CMS
Lessons from a Dying CMS
 

Andere mochten auch

Marketing strategic- Mohamed Attia-Master Discussion
Marketing strategic- Mohamed Attia-Master DiscussionMarketing strategic- Mohamed Attia-Master Discussion
Marketing strategic- Mohamed Attia-Master DiscussionLG Electronics
 
Content: Hvad er en konge uden en strategi?
Content: Hvad er en konge uden en strategi?Content: Hvad er en konge uden en strategi?
Content: Hvad er en konge uden en strategi?Jan Godsk
 
Upf hungary2011-activityreport
Upf hungary2011-activityreportUpf hungary2011-activityreport
Upf hungary2011-activityreportcsili1962
 
Documenting Sexual and Reproductive Health Best Practices in SADC
Documenting Sexual and Reproductive Health Best Practices in SADCDocumenting Sexual and Reproductive Health Best Practices in SADC
Documenting Sexual and Reproductive Health Best Practices in SADCRouzeh Eghtessadi
 

Andere mochten auch (6)

Marketing strategic- Mohamed Attia-Master Discussion
Marketing strategic- Mohamed Attia-Master DiscussionMarketing strategic- Mohamed Attia-Master Discussion
Marketing strategic- Mohamed Attia-Master Discussion
 
Content: Hvad er en konge uden en strategi?
Content: Hvad er en konge uden en strategi?Content: Hvad er en konge uden en strategi?
Content: Hvad er en konge uden en strategi?
 
Past Simple
Past SimplePast Simple
Past Simple
 
Electro hex
Electro hexElectro hex
Electro hex
 
Upf hungary2011-activityreport
Upf hungary2011-activityreportUpf hungary2011-activityreport
Upf hungary2011-activityreport
 
Documenting Sexual and Reproductive Health Best Practices in SADC
Documenting Sexual and Reproductive Health Best Practices in SADCDocumenting Sexual and Reproductive Health Best Practices in SADC
Documenting Sexual and Reproductive Health Best Practices in SADC
 

Ähnlich wie Karwin bill zf-db-zend_con-20071009

MVC with Zend Framework
MVC with Zend FrameworkMVC with Zend Framework
MVC with Zend Frameworkwebholics
 
SD PHP Zend Framework
SD PHP Zend FrameworkSD PHP Zend Framework
SD PHP Zend Frameworkphilipjting
 
SOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesSOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesVagif Abilov
 
6 weeks 6 months live project summer industrial training in cmc limited 2012
6 weeks  6 months live project summer industrial training in cmc limited  20126 weeks  6 months live project summer industrial training in cmc limited  2012
6 weeks 6 months live project summer industrial training in cmc limited 2012CMC Limited
 
DB2 and PHP in Depth on IBM i
DB2 and PHP in Depth on IBM iDB2 and PHP in Depth on IBM i
DB2 and PHP in Depth on IBM iAlan Seiden
 
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON
 
Zend MVC pattern based Framework – Best for Enterprise web applications
Zend MVC pattern based Framework – Best for Enterprise web applicationsZend MVC pattern based Framework – Best for Enterprise web applications
Zend MVC pattern based Framework – Best for Enterprise web applicationsEtisbew Technology Group
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPressTaylor Lovett
 
Headless cms architecture
Headless cms architectureHeadless cms architecture
Headless cms architectureKevin Wenger
 
TechEvent 2019: Oracle to PostgreSQL - a Travel Guide from Practice; Roland S...
TechEvent 2019: Oracle to PostgreSQL - a Travel Guide from Practice; Roland S...TechEvent 2019: Oracle to PostgreSQL - a Travel Guide from Practice; Roland S...
TechEvent 2019: Oracle to PostgreSQL - a Travel Guide from Practice; Roland S...Trivadis
 
DV03 Smooth Migration to Windows Azure
DV03 Smooth Migration to Windows AzureDV03 Smooth Migration to Windows Azure
DV03 Smooth Migration to Windows AzureRonald Widha
 
Developing polyglot persistence applications #javaone 2012
Developing polyglot persistence applications  #javaone 2012Developing polyglot persistence applications  #javaone 2012
Developing polyglot persistence applications #javaone 2012Chris Richardson
 
WordPress Code Architecture
WordPress Code ArchitectureWordPress Code Architecture
WordPress Code ArchitectureMario Peshev
 
Developing polyglot persistence applications (SpringOne India 2012)
Developing polyglot persistence applications (SpringOne India 2012)Developing polyglot persistence applications (SpringOne India 2012)
Developing polyglot persistence applications (SpringOne India 2012)Chris Richardson
 

Ähnlich wie Karwin bill zf-db-zend_con-20071009 (20)

MVC with Zend Framework
MVC with Zend FrameworkMVC with Zend Framework
MVC with Zend Framework
 
SD PHP Zend Framework
SD PHP Zend FrameworkSD PHP Zend Framework
SD PHP Zend Framework
 
SOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesSOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class Libraries
 
6 weeks 6 months live project summer industrial training in cmc limited 2012
6 weeks  6 months live project summer industrial training in cmc limited  20126 weeks  6 months live project summer industrial training in cmc limited  2012
6 weeks 6 months live project summer industrial training in cmc limited 2012
 
DB2 and PHP in Depth on IBM i
DB2 and PHP in Depth on IBM iDB2 and PHP in Depth on IBM i
DB2 and PHP in Depth on IBM i
 
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
 
Cqrs.frameworks
Cqrs.frameworksCqrs.frameworks
Cqrs.frameworks
 
Zend MVC pattern based Framework – Best for Enterprise web applications
Zend MVC pattern based Framework – Best for Enterprise web applicationsZend MVC pattern based Framework – Best for Enterprise web applications
Zend MVC pattern based Framework – Best for Enterprise web applications
 
Ow
OwOw
Ow
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPress
 
Zend Framwork configurations
Zend Framwork configurationsZend Framwork configurations
Zend Framwork configurations
 
Headless cms architecture
Headless cms architectureHeadless cms architecture
Headless cms architecture
 
Einführung in RavenDB
Einführung in RavenDBEinführung in RavenDB
Einführung in RavenDB
 
Zend Framwork presentation
Zend Framwork presentationZend Framwork presentation
Zend Framwork presentation
 
TechEvent 2019: Oracle to PostgreSQL - a Travel Guide from Practice; Roland S...
TechEvent 2019: Oracle to PostgreSQL - a Travel Guide from Practice; Roland S...TechEvent 2019: Oracle to PostgreSQL - a Travel Guide from Practice; Roland S...
TechEvent 2019: Oracle to PostgreSQL - a Travel Guide from Practice; Roland S...
 
DV03 Smooth Migration to Windows Azure
DV03 Smooth Migration to Windows AzureDV03 Smooth Migration to Windows Azure
DV03 Smooth Migration to Windows Azure
 
Extending Zend_Tool
Extending Zend_ToolExtending Zend_Tool
Extending Zend_Tool
 
Developing polyglot persistence applications #javaone 2012
Developing polyglot persistence applications  #javaone 2012Developing polyglot persistence applications  #javaone 2012
Developing polyglot persistence applications #javaone 2012
 
WordPress Code Architecture
WordPress Code ArchitectureWordPress Code Architecture
WordPress Code Architecture
 
Developing polyglot persistence applications (SpringOne India 2012)
Developing polyglot persistence applications (SpringOne India 2012)Developing polyglot persistence applications (SpringOne India 2012)
Developing polyglot persistence applications (SpringOne India 2012)
 

Kürzlich hochgeladen

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 

Karwin bill zf-db-zend_con-20071009

  • 1. Zend Framework Database Quick Start Bill Karwin Product Engineering Manager, Zend Framework
  • 2. Introduction • What’s in the Zend_Db component? • Examples of using each class • Using Zend_Db in MVC applications 2007-10-09 Zend Framework Database Quick Start PAGE 2
  • 3. What is the Zend Framework? • PHP class library • Provides common web application functionality – • Open source so you don’t have to • Emphasis on quality • Use-at-will library of • “Extreme simplicity” object-oriented PHP classes • Popular • 154,000+ lines of code • 100% PHP – works on standard PHP as well as Zend Core • Requires PHP 5.1.4+ 2007-10-09 Zend Framework Database Quick Start PAGE 3
  • 4. What is the Zend Framework? • PHP class library • Free software for development and • Open source deployment • Emphasis on quality • New BSD license • “Extreme simplicity” (similar to PHP itself) • Friendly to commercial • Popular projects • Code is free of legal claims, by virtue of the Contributor License Agreement 2007-10-09 Zend Framework Database Quick Start PAGE 4
  • 5. What is the Zend Framework? • PHP class library • Agile development model • Open source • Frequent evaluation by large user community • Emphasis on quality • Goal of 90% coverage in • “Extreme simplicity” automated tests • Popular • Tests consist of 105,000+ lines of code (40% of total code) • Thorough documentation 2007-10-09 Zend Framework Database Quick Start PAGE 5
  • 6. What is the Zend Framework? • PHP class library • Designed to make development easy • Open source • Solves 80% most needed • Emphasis on quality use cases • “Extreme simplicity” • Extensible; developers implement custom • Popular behavior from the remaining 20% (think of the “long tail”) 2007-10-09 Zend Framework Database Quick Start PAGE 6
  • 7. What is the Zend Framework? • PHP class library • Over 2.2 M downloads – increasing! • Open source • Over 300 contributors • Emphasis on quality • Powers some high-profile • “Extreme simplicity” web sites IBM QEDWiki • Popular Right Media Advertising Exchange Varien Magento bwin International In-Ticketing fav.or.it 2007-10-09 Zend Framework Database Quick Start PAGE 7
  • 8. What’s in the Zend_Db component? • Database Adapters • Common interface to multiple databases • CRUD functions • Supports both PDO and • Quoting SQL native database extensions: Mysqli identifiers and values Oracle OCI8 • Query Profiler IBM DB2 PDO IBM • Query builder PDO Mysql • Table and Row PDO Mssql OO patterns PDO OCI PDO Pgsql PDO Sqlite 2007-10-09 Zend Framework Database Quick Start PAGE 8
  • 9. What’s in the Zend_Db component? • Database Adapters Basic database operations • CRUD functions • insert() • update() • Quoting SQL • delete() identifiers and values • query() • Query Profiler • fetchAll() • Query builder • etc. • Table and Row OO patterns 2007-10-09 Zend Framework Database Quick Start PAGE 9
  • 10. What’s in the Zend_Db component? • Database Adapters • Encourages safer interpolation of values into • CRUD functions SQL strings • Quoting SQL values • Both values and SQL and identifiers identifiers are supported • Query Profiler • Not the same thing as SQL parameters – but those • Query builder are supported too • Table and Row • Both quoting and SQL OO patterns parameters help you to defend against SQL injection issues 2007-10-09 Zend Framework Database Quick Start PAGE 10
  • 11. What’s in the Zend_Db component? • Database Adapters • Measures duration of SQL queries • CRUD functions • Filters by SQL statement • Quoting SQL type or by minimum identifiers and values duration • Query profiler • Reports recorded SQL statements and bound • Query builder parameter values • Table and Row OO patterns 2007-10-09 Zend Framework Database Quick Start PAGE 11
  • 12. What’s in the Zend_Db component? • Database Adapters • Procedural interface to create SELECT queries • CRUD functions • Convenient when you • Quoting SQL need to “build” SQL with identifiers and values application logic • Query Profiler • Helps you to produce valid SQL SELECT syntax • Query builder • Table and Row OO patterns 2007-10-09 Zend Framework Database Quick Start PAGE 12
  • 13. What’s in the Zend_Db component? • Database Adapters • Similar to ActiveRecord pattern in other • CRUD functions frameworks • Quoting SQL • Flexible and extensible identifiers and values base classes for Tables, Rowsets, and Rows • Query Profiler • Emphasis on supporting • Query builder existing database • Table and Row schema; no restrictive OO patterns conventions • Often used in Model classes in MVC apps 2007-10-09 Zend Framework Database Quick Start PAGE 13
  • 14. Database Adapters 2007-10-09 Zend Framework Database Quick Start PAGE 14
  • 15. Connecting to a database • Use the static factory() method of Zend_Db: require_once ‘Zend/Db.php’; $db = Zend_Db::factory(‘Mysqli’, array( ‘host’ => ’localhost’, ‘dbname’ => ’test’, ‘username’=> ’webappuser’, ‘password’=> ’xxxxxxxx’) ); • Returns an object of Zend_Db_Adapter_Mysqli, which extends Zend_Db_Adapter_Abstract 2007-10-09 Zend Framework Database Quick Start PAGE 15
  • 16. Running an SQL query and fetching results • Use the fetchAll() method to return an array of rows. Each row is an associative array: $data = $db->fetchAll(‘SELECT * FROM bugs’); foreach ($data as $row) { echo $row[‘bug_description’]; } • You can fetch rows one-by-one in a loop • You can fetch rows as other structures 2007-10-09 Zend Framework Database Quick Start PAGE 16
  • 17. Preparing an SQL query • Use the prepare() or query() methods to create a Statement object: $stmt = $db->prepare( ‘SELECT * FROM bugs WHERE bug_status = ?’); • Execute once, giving a parameter value: $stmt->execute(array(‘OPEN’)); $openBugs = $stmt->fetchAll(); • Execute a second time, giving another value: $stmt->execute(array(‘CLOSED’)); $closedBugs = $stmt->fetchAll(); 2007-10-09 Zend Framework Database Quick Start PAGE 17
  • 18. Inserting data • Use the insert() method. • Pass the table name, and an associative array mapping columns to values: $db->insert( ‘bugs’, array( ‘bug_description’ => ‘help me’, ‘bug_status’ => ‘NEW’) ); • Get an auto primary key value (if applicable): $bugId = $db->lastInsertId(); 2007-10-09 Zend Framework Database Quick Start PAGE 18
  • 19. Updating data • Use the update() method. • Pass the table name, an associative array mapping columns to new values, and an expression for the WHERE clause: $n = $db->update( ‘bugs’, array(‘bug_status’ => ‘NEW’), ‘bug_id = 123’ ); • Returns the number of rows affected. 2007-10-09 Zend Framework Database Quick Start PAGE 19
  • 20. Deleting data • Use the delete() method. • Pass the table name, and an expression for the WHERE clause: $n = $db->delete(‘bugs’, ‘bug_id = 321’); • Returns the number of rows affected. 2007-10-09 Zend Framework Database Quick Start PAGE 20
  • 21. Retrieving table metadata • Use the describeTable() method: $bugsMetadata = $db->describeTable(‘bugs’); • Returns an array indexed by column name: array( ‘bug_id’ => array(…), ‘bug_description’ => array(…), ‘bug_status’ => array(…), ‘created_on’ => array(…), ‘updated_on’ => array(…), ‘reported_by’ => array(…), ‘assigned_to’ => array(…), ‘verified_by’ => array(…), ) 2007-10-09 Zend Framework Database Quick Start PAGE 21
  • 22. Retrieving table metadata • Each value is an associative array of metadata for the respective column: ‘bug_id’ => array( ‘TABLE_NAME’ => ‘bugs’ ‘COLUMN_NAME’ => ‘bug_id’ ‘COLUMN_POSITION’ => 1 ‘DATA_TYPE’ => ‘INTEGER’ ‘DEFAULT’ => null ‘NULLABLE’ => false ‘LENGTH’ => null ‘SCALE’ => null ‘PRECISION’ => null ‘UNSIGNED’ => null ‘PRIMARY’ => true ‘PRIMARY_POSITION’ => 1 ‘IDENTITY’ => true ), …entries for other columns follow… 2007-10-09 Zend Framework Database Quick Start PAGE 22
  • 23. Quoting SQL 2007-10-09 Zend Framework Database Quick Start PAGE 23
  • 24. Quoting SQL • Important when interpolating strings and PHP variables into SQL • Not the same thing as query parameters Interpolated values add to a SQL query before prepare-time Query parameters supply values to a prepared query at execute-time 2007-10-09 Zend Framework Database Quick Start PAGE 24
  • 25. Quoting SQL values • Use the quote() method to turn a string or variable into a quoted SQL string: $expr = $db->quote(“O’Reilly”); $stmt = $db->query(“SELECT * FROM bugs WHERE bug_reporter = $expr”); note: unlike mysql_real_escape_string(), the quote() method returns a string with quotes. mysql_real_escape_string(“O’Reilly”) returns: O’Reilly $db->quote(“O’Reilly”) returns: ‘O’Reilly’ 2007-10-09 Zend Framework Database Quick Start PAGE 25
  • 26. Quoting SQL values in expressions • Use the quoteInto() method to substitute a scalar into a SQL expression: $whereExpr = $db->quoteInto(‘bug_reporter = ?’, “O’Reilly”); $stmt = $db->query( “SELECT * FROM bugs WHERE $whereExpr”); • Results in the following query: SELECT * FROM bugs WHERE bug_reporter = ‘O’Reilly’ 2007-10-09 Zend Framework Database Quick Start PAGE 26
  • 27. Quoting SQL identifiers • Identifiers are table names, column names, etc. • Use the quoteIdentifier() method : $table = $db->quoteIdentifier(‘My Table’); $stmt = $db->query(“SELECT * FROM $table WHERE …”); • Results in the following query: SELECT * FROM “My Table” WHERE … • Helps if your identifiers contain whitespace, international characters, SQL keywords, etc. 2007-10-09 Zend Framework Database Quick Start PAGE 27
  • 28. Query Profiler 2007-10-09 Zend Framework Database Quick Start PAGE 28
  • 29. Profiling SQL queries • Measures time to execute SQL queries • Useful during development/debugging • The Adapter has a Zend_Db_Profiler object, which is disabled by default $db->getProfiler()->setEnabled(true); • While the profiler is enabled, SQL queries are recorded, with the time it takes them to run. 2007-10-09 Zend Framework Database Quick Start PAGE 29
  • 30. Profiling SQL queries: find longest query $prof = $db->getProfiler(); $prof->setEnabled(true); // run one or more queries with profiler enabled $db->query(…); $db->insert(…); $db->update(…); $max = 0; foreach ($prof->getQueryProfiles() as $q) { if ($q->getElapsedSecs() > $max) { $max = $q->getElapsedSecs(); $longestQuery = $q->getQuery(); } } echo “The longest query ran $max secondsn”; echo “SQL = $longestQueryn”; 2007-10-09 Zend Framework Database Quick Start PAGE 30
  • 31. Profiling SQL queries: filtering • Filtering queries to be recorded // By minimum duration: $prof->setFilterElapsedSecs(5); // By query type: $prof->setFilterQueryType(Zend_Db_Profiler::SELECT | Zend_Db_Profiler::UPDATE); • Filtering queries to be reported $prof->getQueryProfiles(Zend_Db_Profiler::SELECT); 2007-10-09 Zend Framework Database Quick Start PAGE 31
  • 32. Query Builder 2007-10-09 Zend Framework Database Quick Start PAGE 32
  • 33. Building a SELECT query • Use the select() method of the Adapter to get an object of Zend_Db_Select: $select = $db->select(); $select->from(‘bugs’); $select->where(‘bug_status = ?’, ‘NEW’); • Execute the query using the Zend_Db_Select object instead of a SQL string: $data = $db->fetchAll($select); 2007-10-09 Zend Framework Database Quick Start PAGE 33
  • 34. Building a SELECT query • The fluent usage can be convenient: $select = $db->select()->from(‘bugs’) ->where(‘bug_status = ?’, ‘NEW’); • You can mix fluent and traditional usage. • You can add SQL clauses in any order. $select = $db->select()->from(‘bugs’)->order(‘bug_id’); if ($condition == true) { $select->joinNatural(‘other_table’); } 2007-10-09 Zend Framework Database Quick Start PAGE 34
  • 35. Building a SELECT query: other SQL clauses • Additional functions: $select = $db->select() DISTINCT modifier ->distinct() Specify columns ->from(array(‘a’=>‘accounts’), Table correlation names array(‘account_name’, Specify SQL expressions ‘num_bugs’=>‘COUNT(*)’)) Column aliases ->joinLeft(array(‘b’=>‘bugs’), Joins to other tables ‘b.reported_by = GROUP BY clause a.account_name’) HAVING clause ->group(‘a.account_name’) ORDER BY clause ->having(‘num_bugs < 5’) LIMIT clause ->order(‘a.account_name ASC’) ->limit(10, 20); 2007-10-09 Zend Framework Database Quick Start PAGE 35
  • 36. Table and Row Object-Oriented Patterns 2007-10-09 Zend Framework Database Quick Start PAGE 36
  • 37. Table Data Gateway • Like the ActiveRecord pattern, this provides a simple OO interface for a database table. • Table Data Gateway and Row Data Gateway patterns are based on Martin Fowler’s “Patterns of Enterprise Architecture.” • Base classes for Table, Row, and Rowset are extensible, to allow you to define business logic. • You may use Table objects in your MVC Model classes, or as your MVC Models. 2007-10-09 Zend Framework Database Quick Start PAGE 37
  • 38. Table Data Gateway: define a table • Start by defining a class for each table: class Bugs extends Zend_Db_Table_Abstract { protected $_name = ‘bugs’; } • Default code is inherited from the base Zend_Db_Table_Abstract class. • You don’t need to define $_name if the class name matches the name of the table in the database. 2007-10-09 Zend Framework Database Quick Start PAGE 38
  • 39. Table Data Gateway: instantiate a table • Option #1: pass the database Adapter object to the Table constructor: $bugsTable = new Bugs( $db ); • Option #2: set a default Adapter for all Tables: Zend_Db_Table_Abstract::setDefaultAdapter($db); $bugsTable = new Bugs(); • Option #3: save the Adapter object in Zend_Registry and reference it later by key: Zend_Registry::set(‘myDb’, $db); $bugsTable = new Bugs( ‘myDb’ ); 2007-10-09 Zend Framework Database Quick Start PAGE 39
  • 40. Table Data Gateway: query a table • Use the fetchAll() method to get a Rowset with all rows matching a condition you specify: $rowset = $bugsTable->fetchAll(“bug_status = ‘OPEN’”); • A Rowset object is iterable and countable. • A Rowset is a collection of Row objects. • A Row has an accessor for each column. foreach ($rowset as $row) { echo “$row->bug_id: $row->bug_descriptionn”; } 2007-10-09 Zend Framework Database Quick Start PAGE 40
  • 41. Table Data Gateway: find by primary key • Use the find() method with a primary key value or an array of values: $bugsTable = new Bugs(); $rowset1 = $bugsTable->find(123); $rowset2 = $bugsTable->find( array(123, 321) ); • $rowset1 contains 0 or 1 Row • $rowset2 contains up to 2 Rows 2007-10-09 Zend Framework Database Quick Start PAGE 41
  • 42. Table Data Gateway: UPDATE • Get the Row you want to update: $bugsTable = new Bugs(); $rowset = $bugsTable->find(123); $row = $rowset->current(); • Set a column value using the accessor: $row->bug_description = ‘New description’; • Use the save() method of the Row object to post the change to the database: $row->save(); 2007-10-09 Zend Framework Database Quick Start PAGE 42
  • 43. Table Data Gateway: INSERT • Use the createRow() method of the Table object to get a blank Row: $bugsTable = new Bugs(); $newRow = $bugsTable->createRow(); • Set Row fields: $newRow->bug_description = ‘help me’; $newRow->bug_status = ‘NEW’; • Use the save() method of new Row object to post it to the database: $newRow->save(); 2007-10-09 Zend Framework Database Quick Start PAGE 43
  • 44. Table Data Gateway: DELETE • Get a Row you want to delete: $bugsTable = new Bugs(); $row = $bugsTable->find(123)->current(); • Use the delete() method of the Row object: $row->delete(); 2007-10-09 Zend Framework Database Quick Start PAGE 44
  • 45. Table Data Gateway: relationships • Assume an Entity-Relationship like this: reported by bugs accounts • Get a Row from the Accounts table: $accountsTable = new Accounts(); $account = $accountsTable->find(‘bill’)->current(); • Find a Rowset in related table Bugs: $reportedBugs = $account->findBugs(); 2007-10-09 Zend Framework Database Quick Start PAGE 45
  • 46. Table Data Gateway: relationships • You also can get the parent row. Start with the dependent row in Bugs: $bugsTable = new Bugs(); $bug = $bugsTable->find(123)->current(); • Find the parent Row in related table Accounts: $reporter = $bug->findParentAccounts(); 2007-10-09 Zend Framework Database Quick Start PAGE 46
  • 47. Table Data Gateway: relationships • Declare table relationships in the table class: class Accounts extends Zend_Db_Table_Abstract { protected $_name = ‘accounts’; } class Bugs extends Zend_Db_Table_Abstract { protected $_name = ‘bugs’; } protected $_referenceMap = array( ‘Reporter’ => array( ‘columns’ => array(‘reported_by’), ‘refTableClass’ => ‘Accounts’ )); } 2007-10-09 Zend Framework Database Quick Start PAGE 47
  • 48. Table Data Gateway: customization • You can add custom logic to a Table class: class Bugs extends Zend_Db_Table_Abstract { protected $_name = ‘bugs’; public function insert(array $data) { if (empty($data['created_on'])) { $data['created_on'] = time(); } return parent::insert($data); } } 2007-10-09 Zend Framework Database Quick Start PAGE 48
  • 49. Using Zend_Db in MVC Applications 2007-10-09 Zend Framework Database Quick Start PAGE 49
  • 50. Using Zend_Db in MVC Applications • Each Model class in the MVC architecture encapsulates data and operations on data for a logical domain within your application. • You can use either Zend_Db_Table objects or direct SQL queries to implement persistence for Model data. • Common to define Models using an “is-a” relationship to Zend_Db_Table, but it can be more flexible to use a “has-a” relationship instead. 2007-10-09 Zend Framework Database Quick Start PAGE 50
  • 51. Using Zend_Db in MVC Applications • Simple Models can extend directly from Zend_Db_Table_Abstract: class Countries extends Zend_Db_Table_Abstract { protected $_name = ‘countries’; } • Good if this Model corresponds one-to-one with a single physical database table. 2007-10-09 Zend Framework Database Quick Start PAGE 51
  • 52. Using Zend_Db in MVC Applications • More complex Models use multiple Tables, or else Db Adapter methods to execute SQL. class QuarterlyReport // extends nothing { protected $_salesTable; protected $_productsTable; protected $_dbAdapter; // for direct SQL queries public function getReport($quarter) { … } } • Good if you want this Model’s interface to be decoupled from the physical database structure. 2007-10-09 Zend Framework Database Quick Start PAGE 52
  • 53. Recap of Zend_Db • Adapters to PHP database extensions • Quoting SQL identifiers and values • Query profiler • SELECT query builder • Table Data Gateway & Row Data Gateway 2007-10-09 Zend Framework Database Quick Start PAGE 53