SlideShare a Scribd company logo
1 of 30
Download to read offline
Propel Your PHP Applications
                         Hans Lellelid
         International PHP Conference
                           2007-11-06
Introduction
• My name is Hans Lellelid
• Developer + manager at Applied Security,
  Inc. (near Washington DC).
• I wrote/ported original Propel.
• I currently manage the project with David
  Zülke – and an ever-growing team of
  developers.




Hans Lellelid: Propel Your PHP Applications    2
This Talk
•   Overview of Propel
•   A typical work cycle
•   More in-depth usage
•   Advanced features
•   Slides available at
    http://propel.phpdb.org/presentations/




Hans Lellelid: Propel Your PHP Applications      3
Pre-Flight Check
                       Going over the basics.




Hans Lellelid: Propel Your PHP Applications     4
Fact Sheet
• Propel is an ORM tool for PHP5.
      – It is also a code (and DDL) generator.
• Based on Apache Torque.
• Includes runtime and generator
  frameworks.
• Uses PDO (v1.2 uses Creole)
• Generator uses Phing tasks to create the
  PHP and SQL files.
• Installs using PEAR installer.

Hans Lellelid: Propel Your PHP Applications      5
ORM Patterns in PHP
• The most common alternative ORM pattern
  in PHP is ActiveRecord.
      – (Thank you, Ruby on Rails!)
• Propel is not an ActiveRecord
  implementation: it is a Row Data Gateway
  + Table Data Gateway implementation.
• Key differences:
      – Clean division of labor between table
        operation objects and row instances.
      – RDG and TDG are inherently simpler, more
        transparent, models.
Hans Lellelid: Propel Your PHP Applications    6
Motivations & Purpose
• Created because nothing comparable
  existed for PHP at the time.
• Designed to facilitate prototyping and RAD
• Basic Philosophy: Database tasks should
  feel as simple as they actually are.
• Designed for “enterprise” frameworks.




Hans Lellelid: Propel Your PHP Applications   7
Requirements
• PHP 5
      – Version 1.3 requires PHP >= 5.2
      – SPL, PDO (1.3), XML, XSLT
• Phing
• A supported database. Currently Propel
  supports: MySQL, PostgreSQL, MSSQL,
  Oracle, SQLite




Hans Lellelid: Propel Your PHP Applications   8
Propel will ...
• Generate classes to represent your
  database (model) in an OOP way.
      – “Object” classes for rows (RDG)
      – “Peer” classes for table operations (TDG)
• Build SQL (DDL) to initialize your database.
• Use unit-of-work pattern to wrap nested
  inserts in transactions.
• Provide Exception-based error handling.
• Allow you to avoid SQL (if you want).
• Type-cast output and escape input.
Hans Lellelid: Propel Your PHP Applications         9
But Propel won't ...
• Build forms, reports, or other display stuff.
      – Several full frameworks are built around
        Propel to provide this (e.g Symfony, Agavi)
• Help you design your database.
• Prevent you from writing insecure code.
• Replenish essential electrolytes after a hard
  workout.




Hans Lellelid: Propel Your PHP Applications       10
Flight Plan
               A Typical Propel Work Cycle




Hans Lellelid: Propel Your PHP Applications     11
A Typical Workflow
•   Design Database in XML (schema.xml)
•   Configure generator (build.properties)
•   Configure runtime (runtime-conf.xml)
•   Build SQL DDL and PHP classes.
•   (Maybe) initialize database.
•   Use newly-built objects in your application.




Hans Lellelid: Propel Your PHP Applications   12
schema.xml
• The schema.xml is the single authority for
  your data model.
• Written in [quite intuitive] XML
    <?xml version=quot;1.0quot;?>
    <database name=quot;demoquot;>
        <table name=quot;sessionquot;>
            <column name=quot;idquot; type=quot;integerquot; primaryKey=quot;truequot; />
            <column name=quot;namequot; type=quot;varcharquot; size=quot;255quot; />
            <column name=quot;roomquot; type=quot;varcharquot; size=quot;16quot; />
            <column name=quot;speakerquot; type=quot;varcharquot; size=quot;32quot; />
        </table>
    </database>


• Will be validated by build process (DTD and
  schema provided).
Hans Lellelid: Propel Your PHP Applications                         13
build.properties
• Generator uses “properties” files (Phing)
• Propel needs to know (at least) your
  RDBMS and project name.
• It's often simplest to start with the
  provided “bookstore” example.
• Example minimal build.properties:
    propel.project = myproj
    propel.database = mysql
    propel.database.url = mysql:dbname=test




Hans Lellelid: Propel Your PHP Applications   14
runtime-conf.xml
• Runtime config expressed in XML.
• Configures connection and (optionally)
  PEAR logging facility.
• Gets converted to PHP by build process.
    <config>
        <propel>
            <datasources default=quot;myprojquot;>
                <datasource id=quot;myprojquot;>
                    <adapter>mysql</adapter>
                    <connection>
                        <dsn>mysql:dbname=test</dsn>
                    </connection>
                </datasource>
            </datasources>
        </propel>
    </config>

Hans Lellelid: Propel Your PHP Applications            15
Build!
• Run propel-gen /path/to/projdir to
  build the SQL DDL and PHP classes.
• Watch output for errors. (They're red.)




Hans Lellelid: Propel Your PHP Applications        16
Initialize DB
• Use propel-gen /path/to/projdir
  insert-sql to run the generated DDL
  statements against your configured
  database.
• This will delete any existing data!




Hans Lellelid: Propel Your PHP Applications     17
Start using new OM
• Initialize Propel
     require_once 'propel/Propel.php';
     Propel::init('/path/to/myproj-conf.php');

• Configure your include_path to include the
  output directory.
      – Propel 1.3 uses SPL autoload.
• Begin reading and writing DB rows with
  your new object model.



Hans Lellelid: Propel Your PHP Applications      18
Cruising Altitude
        Getting comfortable with Propel.




Hans Lellelid: Propel Your PHP Applications   19
Column Types
• Propel uses an abstract subset of SQL
  types.
• SQL types are mapped to specific PHP
  types.
• You can override the SQL type for a
  column.
• Temporal values (DATE, TIME, TIMESTAMP)
  will use PHP DateTime objects.



Hans Lellelid: Propel Your PHP Applications   20
Expressing Relationships
• Relationships between tables are defined
  using foreign keys.
      – Even for systems that don't support true FK
        constraints.
• Propel supports single or composite foreign
  keys.
• Support for deletion cascading emulation.
• The related objects can be get/set just like
  simple column values.

Hans Lellelid: Propel Your PHP Applications      21
Selecting Rows
• retrieveByPK() static method exists to
  select a single row.
• Criteria provides an OO approach to
  building queries.
• Smart handling of column types.
• Multiple “Criterion” objects can be grouped
  together to form complex queries.
• You can also use SQL, if you prefer.


Hans Lellelid: Propel Your PHP Applications   22
Customization
• Build properties customize code generation.
• Override method and constant naming from
  the schema.xml
• Empty stub object & peer classes for
  custom methods:
      – New methods or
      – Override parent (base) methods




Hans Lellelid: Propel Your PHP Applications   23
Over-Drive
          Wait ... I thought we were using
                airplane metaphors.



Hans Lellelid: Propel Your PHP Applications    24
Locator Objects (LOBs)
• LOB columns returned as PHP streams.
      – This is the PDO design (though there are
        some exceptions).
• Mutator methods support streams or
  (string) file contents.




Hans Lellelid: Propel Your PHP Applications        25
Inheritance
• Propel supports table-per-class-hierarchy
  inheritance.
• Subclasses can be enumerated in the
  schema.xml (faster) or resolved at runtime
  (more flexible).
• Plans in place for other inheritance models.




Hans Lellelid: Propel Your PHP Applications    26
Other Features
• Reverse engineer existing databases
  (requires Creole)
• Import and export data as XML
• Generate Graphviz ERD from schema.xml
• Represent trees in SQL using nested set
  approach.




Hans Lellelid: Propel Your PHP Applications   27
Extension Paths
• Integrating with other Phing projects
• Custom platform classes
      – Affects generation of SQL DDL
• Custom builder classes
      – Determine how your classes are built.




Hans Lellelid: Propel Your PHP Applications     28
The 2.0 Horizon
• Criteria redesign
• New inheritance models
• Eagerly awaiting PHP6 (or 5.3)
      – Namespaces
      – Late static binding
• Plugin-based builder framework.




Hans Lellelid: Propel Your PHP Applications   29
On Behalf of the Flight
                    Crew ...
                      Thanks for listening. :)



Hans Lellelid: Propel Your PHP Applications      30

More Related Content

What's hot

Automated Deployment With Phing
Automated Deployment With PhingAutomated Deployment With Phing
Automated Deployment With PhingDaniel Cousineau
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with PerlDave Cross
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using DjangoNathan Eror
 
Getting started with Catalyst and extjs
Getting started with Catalyst and extjsGetting started with Catalyst and extjs
Getting started with Catalyst and extjsPeter Edwards
 
03 form-data
03 form-data03 form-data
03 form-datasnopteck
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with PerlDave Cross
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial之宇 趙
 
Perl in the Internet of Things
Perl in the Internet of ThingsPerl in the Internet of Things
Perl in the Internet of ThingsDave Cross
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHPNick Belhomme
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterZendCon
 
New Features in PHP 5.3
New Features in PHP 5.3New Features in PHP 5.3
New Features in PHP 5.3Bradley Holt
 
Introduction to Web Programming with Perl
Introduction to Web Programming with PerlIntroduction to Web Programming with Perl
Introduction to Web Programming with PerlDave Cross
 
Web Development in Perl
Web Development in PerlWeb Development in Perl
Web Development in PerlNaveen Gupta
 

What's hot (20)

Automated Deployment With Phing
Automated Deployment With PhingAutomated Deployment With Phing
Automated Deployment With Phing
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using Django
 
Getting started with Catalyst and extjs
Getting started with Catalyst and extjsGetting started with Catalyst and extjs
Getting started with Catalyst and extjs
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
03 form-data
03 form-data03 form-data
03 form-data
 
PHP - Introduction to PHP Date and Time Functions
PHP -  Introduction to  PHP Date and Time FunctionsPHP -  Introduction to  PHP Date and Time Functions
PHP - Introduction to PHP Date and Time Functions
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
Perl in the Internet of Things
Perl in the Internet of ThingsPerl in the Internet of Things
Perl in the Internet of Things
 
Os Furlong
Os FurlongOs Furlong
Os Furlong
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
 
Os Pruett
Os PruettOs Pruett
Os Pruett
 
New Features in PHP 5.3
New Features in PHP 5.3New Features in PHP 5.3
New Features in PHP 5.3
 
Introduction to Web Programming with Perl
Introduction to Web Programming with PerlIntroduction to Web Programming with Perl
Introduction to Web Programming with Perl
 
Web Development in Perl
Web Development in PerlWeb Development in Perl
Web Development in Perl
 
Os Bunce
Os BunceOs Bunce
Os Bunce
 

Similar to Propel Your PHP Applications

Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Espen Brækken
 
PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019
PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019
PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019Dave Stokes
 
PHP, The X DevAPI, and the MySQL Document Store Presented January 23rd, 20...
PHP,  The X DevAPI,  and the  MySQL Document Store Presented January 23rd, 20...PHP,  The X DevAPI,  and the  MySQL Document Store Presented January 23rd, 20...
PHP, The X DevAPI, and the MySQL Document Store Presented January 23rd, 20...Dave Stokes
 
Enterprise Perl
Enterprise PerlEnterprise Perl
Enterprise PerlDave Cross
 
Big data processing using HPCC Systems Above and Beyond Hadoop
Big data processing using HPCC Systems Above and Beyond HadoopBig data processing using HPCC Systems Above and Beyond Hadoop
Big data processing using HPCC Systems Above and Beyond HadoopHPCC Systems
 
Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016
Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016
Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016MLconf
 
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...LEDC 2016
 
Intro to drupal_7_architecture
Intro to drupal_7_architectureIntro to drupal_7_architecture
Intro to drupal_7_architectureHai Vo Hoang
 
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
 
Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0Quang Ngoc
 
Enhancing Domain Specific Language Implementations Through Ontology
Enhancing Domain Specific Language Implementations Through OntologyEnhancing Domain Specific Language Implementations Through Ontology
Enhancing Domain Specific Language Implementations Through OntologyChunhua Liao
 
Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)Stefan Koopmanschap
 
Sql php-vibrant course-mumbai(1)
Sql php-vibrant course-mumbai(1)Sql php-vibrant course-mumbai(1)
Sql php-vibrant course-mumbai(1)vibrantuser
 
Php Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi MensahPhp Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi MensahPHP Barcelona Conference
 

Similar to Propel Your PHP Applications (20)

Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex
 
PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019
PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019
PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019
 
PHP, The X DevAPI, and the MySQL Document Store Presented January 23rd, 20...
PHP,  The X DevAPI,  and the  MySQL Document Store Presented January 23rd, 20...PHP,  The X DevAPI,  and the  MySQL Document Store Presented January 23rd, 20...
PHP, The X DevAPI, and the MySQL Document Store Presented January 23rd, 20...
 
Enterprise Perl
Enterprise PerlEnterprise Perl
Enterprise Perl
 
Big data processing using HPCC Systems Above and Beyond Hadoop
Big data processing using HPCC Systems Above and Beyond HadoopBig data processing using HPCC Systems Above and Beyond Hadoop
Big data processing using HPCC Systems Above and Beyond Hadoop
 
Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016
Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016
Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016
 
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
 
Intro to drupal_7_architecture
Intro to drupal_7_architectureIntro to drupal_7_architecture
Intro to drupal_7_architecture
 
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
 
Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0
 
wamp.ppt
wamp.pptwamp.ppt
wamp.ppt
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Enhancing Domain Specific Language Implementations Through Ontology
Enhancing Domain Specific Language Implementations Through OntologyEnhancing Domain Specific Language Implementations Through Ontology
Enhancing Domain Specific Language Implementations Through Ontology
 
Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)
 
PHP ITCS 323
PHP ITCS 323PHP ITCS 323
PHP ITCS 323
 
Sql php-vibrant course-mumbai(1)
Sql php-vibrant course-mumbai(1)Sql php-vibrant course-mumbai(1)
Sql php-vibrant course-mumbai(1)
 
Php Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi MensahPhp Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi Mensah
 
Current state-of-php
Current state-of-phpCurrent state-of-php
Current state-of-php
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 

Recently uploaded

/:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc...
/:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc.../:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc...
/:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc...lizamodels9
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMANIlamathiKannappan
 
Sales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessSales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessAggregage
 
VIP Call Girls Pune Kirti 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Kirti 8617697112 Independent Escort Service PuneVIP Call Girls Pune Kirti 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Kirti 8617697112 Independent Escort Service PuneCall girls in Ahmedabad High profile
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMRavindra Nath Shukla
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdfRenandantas16
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.Aaiza Hassan
 
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...lizamodels9
 
Call Girls in Gomti Nagar - 7388211116 - With room Service
Call Girls in Gomti Nagar - 7388211116  - With room ServiceCall Girls in Gomti Nagar - 7388211116  - With room Service
Call Girls in Gomti Nagar - 7388211116 - With room Servicediscovermytutordmt
 
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999Tina Ji
 
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...lizamodels9
 
Keppel Ltd. 1Q 2024 Business Update Presentation Slides
Keppel Ltd. 1Q 2024 Business Update  Presentation SlidesKeppel Ltd. 1Q 2024 Business Update  Presentation Slides
Keppel Ltd. 1Q 2024 Business Update Presentation SlidesKeppelCorporation
 
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...anilsa9823
 
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,noida100girls
 
Catalogue ONG NUOC PPR DE NHAT .pdf
Catalogue ONG NUOC PPR DE NHAT      .pdfCatalogue ONG NUOC PPR DE NHAT      .pdf
Catalogue ONG NUOC PPR DE NHAT .pdfOrient Homes
 
Tech Startup Growth Hacking 101 - Basics on Growth Marketing
Tech Startup Growth Hacking 101  - Basics on Growth MarketingTech Startup Growth Hacking 101  - Basics on Growth Marketing
Tech Startup Growth Hacking 101 - Basics on Growth MarketingShawn Pang
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communicationskarancommunications
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Dave Litwiller
 
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurVIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurSuhani Kapoor
 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageMatteo Carbone
 

Recently uploaded (20)

/:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc...
/:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc.../:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc...
/:Call Girls In Jaypee Siddharth - 5 Star Hotel New Delhi ➥9990211544 Top Esc...
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMAN
 
Sales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessSales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for Success
 
VIP Call Girls Pune Kirti 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Kirti 8617697112 Independent Escort Service PuneVIP Call Girls Pune Kirti 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Kirti 8617697112 Independent Escort Service Pune
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSM
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.
 
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
 
Call Girls in Gomti Nagar - 7388211116 - With room Service
Call Girls in Gomti Nagar - 7388211116  - With room ServiceCall Girls in Gomti Nagar - 7388211116  - With room Service
Call Girls in Gomti Nagar - 7388211116 - With room Service
 
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
 
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
 
Keppel Ltd. 1Q 2024 Business Update Presentation Slides
Keppel Ltd. 1Q 2024 Business Update  Presentation SlidesKeppel Ltd. 1Q 2024 Business Update  Presentation Slides
Keppel Ltd. 1Q 2024 Business Update Presentation Slides
 
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
 
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
 
Catalogue ONG NUOC PPR DE NHAT .pdf
Catalogue ONG NUOC PPR DE NHAT      .pdfCatalogue ONG NUOC PPR DE NHAT      .pdf
Catalogue ONG NUOC PPR DE NHAT .pdf
 
Tech Startup Growth Hacking 101 - Basics on Growth Marketing
Tech Startup Growth Hacking 101  - Basics on Growth MarketingTech Startup Growth Hacking 101  - Basics on Growth Marketing
Tech Startup Growth Hacking 101 - Basics on Growth Marketing
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communications
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
 
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurVIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usage
 

Propel Your PHP Applications

  • 1. Propel Your PHP Applications Hans Lellelid International PHP Conference 2007-11-06
  • 2. Introduction • My name is Hans Lellelid • Developer + manager at Applied Security, Inc. (near Washington DC). • I wrote/ported original Propel. • I currently manage the project with David Zülke – and an ever-growing team of developers. Hans Lellelid: Propel Your PHP Applications 2
  • 3. This Talk • Overview of Propel • A typical work cycle • More in-depth usage • Advanced features • Slides available at http://propel.phpdb.org/presentations/ Hans Lellelid: Propel Your PHP Applications 3
  • 4. Pre-Flight Check Going over the basics. Hans Lellelid: Propel Your PHP Applications 4
  • 5. Fact Sheet • Propel is an ORM tool for PHP5. – It is also a code (and DDL) generator. • Based on Apache Torque. • Includes runtime and generator frameworks. • Uses PDO (v1.2 uses Creole) • Generator uses Phing tasks to create the PHP and SQL files. • Installs using PEAR installer. Hans Lellelid: Propel Your PHP Applications 5
  • 6. ORM Patterns in PHP • The most common alternative ORM pattern in PHP is ActiveRecord. – (Thank you, Ruby on Rails!) • Propel is not an ActiveRecord implementation: it is a Row Data Gateway + Table Data Gateway implementation. • Key differences: – Clean division of labor between table operation objects and row instances. – RDG and TDG are inherently simpler, more transparent, models. Hans Lellelid: Propel Your PHP Applications 6
  • 7. Motivations & Purpose • Created because nothing comparable existed for PHP at the time. • Designed to facilitate prototyping and RAD • Basic Philosophy: Database tasks should feel as simple as they actually are. • Designed for “enterprise” frameworks. Hans Lellelid: Propel Your PHP Applications 7
  • 8. Requirements • PHP 5 – Version 1.3 requires PHP >= 5.2 – SPL, PDO (1.3), XML, XSLT • Phing • A supported database. Currently Propel supports: MySQL, PostgreSQL, MSSQL, Oracle, SQLite Hans Lellelid: Propel Your PHP Applications 8
  • 9. Propel will ... • Generate classes to represent your database (model) in an OOP way. – “Object” classes for rows (RDG) – “Peer” classes for table operations (TDG) • Build SQL (DDL) to initialize your database. • Use unit-of-work pattern to wrap nested inserts in transactions. • Provide Exception-based error handling. • Allow you to avoid SQL (if you want). • Type-cast output and escape input. Hans Lellelid: Propel Your PHP Applications 9
  • 10. But Propel won't ... • Build forms, reports, or other display stuff. – Several full frameworks are built around Propel to provide this (e.g Symfony, Agavi) • Help you design your database. • Prevent you from writing insecure code. • Replenish essential electrolytes after a hard workout. Hans Lellelid: Propel Your PHP Applications 10
  • 11. Flight Plan A Typical Propel Work Cycle Hans Lellelid: Propel Your PHP Applications 11
  • 12. A Typical Workflow • Design Database in XML (schema.xml) • Configure generator (build.properties) • Configure runtime (runtime-conf.xml) • Build SQL DDL and PHP classes. • (Maybe) initialize database. • Use newly-built objects in your application. Hans Lellelid: Propel Your PHP Applications 12
  • 13. schema.xml • The schema.xml is the single authority for your data model. • Written in [quite intuitive] XML <?xml version=quot;1.0quot;?> <database name=quot;demoquot;> <table name=quot;sessionquot;> <column name=quot;idquot; type=quot;integerquot; primaryKey=quot;truequot; /> <column name=quot;namequot; type=quot;varcharquot; size=quot;255quot; /> <column name=quot;roomquot; type=quot;varcharquot; size=quot;16quot; /> <column name=quot;speakerquot; type=quot;varcharquot; size=quot;32quot; /> </table> </database> • Will be validated by build process (DTD and schema provided). Hans Lellelid: Propel Your PHP Applications 13
  • 14. build.properties • Generator uses “properties” files (Phing) • Propel needs to know (at least) your RDBMS and project name. • It's often simplest to start with the provided “bookstore” example. • Example minimal build.properties: propel.project = myproj propel.database = mysql propel.database.url = mysql:dbname=test Hans Lellelid: Propel Your PHP Applications 14
  • 15. runtime-conf.xml • Runtime config expressed in XML. • Configures connection and (optionally) PEAR logging facility. • Gets converted to PHP by build process. <config> <propel> <datasources default=quot;myprojquot;> <datasource id=quot;myprojquot;> <adapter>mysql</adapter> <connection> <dsn>mysql:dbname=test</dsn> </connection> </datasource> </datasources> </propel> </config> Hans Lellelid: Propel Your PHP Applications 15
  • 16. Build! • Run propel-gen /path/to/projdir to build the SQL DDL and PHP classes. • Watch output for errors. (They're red.) Hans Lellelid: Propel Your PHP Applications 16
  • 17. Initialize DB • Use propel-gen /path/to/projdir insert-sql to run the generated DDL statements against your configured database. • This will delete any existing data! Hans Lellelid: Propel Your PHP Applications 17
  • 18. Start using new OM • Initialize Propel require_once 'propel/Propel.php'; Propel::init('/path/to/myproj-conf.php'); • Configure your include_path to include the output directory. – Propel 1.3 uses SPL autoload. • Begin reading and writing DB rows with your new object model. Hans Lellelid: Propel Your PHP Applications 18
  • 19. Cruising Altitude Getting comfortable with Propel. Hans Lellelid: Propel Your PHP Applications 19
  • 20. Column Types • Propel uses an abstract subset of SQL types. • SQL types are mapped to specific PHP types. • You can override the SQL type for a column. • Temporal values (DATE, TIME, TIMESTAMP) will use PHP DateTime objects. Hans Lellelid: Propel Your PHP Applications 20
  • 21. Expressing Relationships • Relationships between tables are defined using foreign keys. – Even for systems that don't support true FK constraints. • Propel supports single or composite foreign keys. • Support for deletion cascading emulation. • The related objects can be get/set just like simple column values. Hans Lellelid: Propel Your PHP Applications 21
  • 22. Selecting Rows • retrieveByPK() static method exists to select a single row. • Criteria provides an OO approach to building queries. • Smart handling of column types. • Multiple “Criterion” objects can be grouped together to form complex queries. • You can also use SQL, if you prefer. Hans Lellelid: Propel Your PHP Applications 22
  • 23. Customization • Build properties customize code generation. • Override method and constant naming from the schema.xml • Empty stub object & peer classes for custom methods: – New methods or – Override parent (base) methods Hans Lellelid: Propel Your PHP Applications 23
  • 24. Over-Drive Wait ... I thought we were using airplane metaphors. Hans Lellelid: Propel Your PHP Applications 24
  • 25. Locator Objects (LOBs) • LOB columns returned as PHP streams. – This is the PDO design (though there are some exceptions). • Mutator methods support streams or (string) file contents. Hans Lellelid: Propel Your PHP Applications 25
  • 26. Inheritance • Propel supports table-per-class-hierarchy inheritance. • Subclasses can be enumerated in the schema.xml (faster) or resolved at runtime (more flexible). • Plans in place for other inheritance models. Hans Lellelid: Propel Your PHP Applications 26
  • 27. Other Features • Reverse engineer existing databases (requires Creole) • Import and export data as XML • Generate Graphviz ERD from schema.xml • Represent trees in SQL using nested set approach. Hans Lellelid: Propel Your PHP Applications 27
  • 28. Extension Paths • Integrating with other Phing projects • Custom platform classes – Affects generation of SQL DDL • Custom builder classes – Determine how your classes are built. Hans Lellelid: Propel Your PHP Applications 28
  • 29. The 2.0 Horizon • Criteria redesign • New inheritance models • Eagerly awaiting PHP6 (or 5.3) – Namespaces – Late static binding • Plugin-based builder framework. Hans Lellelid: Propel Your PHP Applications 29
  • 30. On Behalf of the Flight Crew ... Thanks for listening. :) Hans Lellelid: Propel Your PHP Applications 30