Ticket #267 (closed task: fixed)

Opened 4 years ago

Last modified 12 months ago

Change Propel to use PDO for runtime db abstraction

Reported by: hans Owned by: hans
Priority: normal Milestone: 1.3
Component: Generator Version: devel
Severity: normal Keywords: pdo
Cc:

Description

When the Propel project started, there were several PHP DBAL (DB abstraction layer) options, but none of them fit our needs. In particular we needed:

  1. A PHP5-native layer that would throw db errors as exceptions
  2. A layer that would do a better jobs than the alternatives at providing metadata
  3. A completely OO layer that wouldn't rely on associative arrays or other idiosyncratic conventions in the API
  4. ... and just in general, it needed to be good, readable, documented, clean code.

Creole was thus born a sub-project of Propel, and indeed, Creole has become quite popular in its own right.

In the time since the project's inception, however, PDO has become stable and a part of the PHP distribution. Other than the metadata requirement, PDO fits Propel's needs very nicely, and the fact that this is compiled code should result in a big speed improvement. Hence, it makes sense to switch to using PDO for Propel's runtime DBAL.

PDO's API is very similar to Creole's and in general has support for the features we need. There are, however, a few challenges that we need to address in porting Propel to use PDO.

  1. PDO doesn't support nested transactions (or, more precisely, it doesn't support the API the way Creole does, although none of the Creole drivers actually implement the nested transactions at this time). PDO will throw an exception if you attempt to begin a transaction when another one is already in-progress. This doesn't work well with Propel's model of nested units of work. (I also opened a PHP feature request for this:  http://pecl.php.net/bugs/bug.php?id=7718)
  2. PDO doesn't support LIMIT. This makes sense, it was never really the job of a DBAL to support LIMIT/OFFSET stuff, but alas convenience won out with Creole :)
  3. PDO doesn't handle temporal type conversion timestamps. This also makes sense, but adds some more responsibility to the Propel DBAdapter classes.

Change History

Changed 4 years ago by hans

Preliminary implementation added in changeset:372

Note that we are using PDO for both the generator SQL execution and the runtime environment.

The propel.databse.url must be updated to be a PDO DSN in your build.properties (e.g.):

propel.database = sqlite
propel.database.url = sqlite2:/tmp/bookstore.db

For runtime environment, the config file needs to look like:

[datasources]
default=bookstore
bookstore.dsn="sqlite2:/tmp/bookstore.db"
bookstore.adapter=sqlite

Changed 3 years ago by hans

Added preliminary version of these changes to 1.3 branch in changeset:444

Changed 3 years ago by hans

  • milestone changed from 2.0 to 1.3

Changed 3 years ago by hans

Renamed doSelectRS() -> doSelectStmt() in changeset:474

Changed 3 years ago by hans

  • status changed from new to closed
  • resolution set to fixed

Closing this ticket, as the runtime and basic generator Creole -> PDO migration is complete. The remaining task that must be addressed is the integration of a new reverse-engineering platform, for which ticket:301 has been created.

Changed 3 years ago by hans

Note that the runtime configuration format has been reverted to XML in order to support the new autolaod features.

For example:

<config>
 <propel>
  <datasources default="bookstore">   
   <datasource id="bookstore">
    <!-- the Propel adapter (usually same as phptype of connection DSN) -->
    <adapter>sqlite</adapter>       
    <connection>
     <dsn>sqlite2:/tmp/bookstore.db</dsn>
     <!--
     For MySQL and Oracle you must specify username + 
     password separate from DSN:
     <user>testuser</user>
     <password>password</password>
     -->
     <options>
      <option id="ATTR_PERSISTENT">false</option>
     </options>
    </connection>
   </datasource>
  </datasources>
 </propel>
</config>
Note: See TracTickets for help on using tickets.