README 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. PHP Data Objects
  2. ================
  3. Concept: Data Access Abstraction
  4. Goals:
  5. 1/ Be light-weight
  6. 2/ Provide common API for common database operations
  7. 3/ Be performant
  8. 4/ Keep majority of PHP specific stuff in the PDO core (such as persistent
  9. resource management); drivers should only have to worry about getting the
  10. data and not about PHP internals.
  11. Transactions and autocommit
  12. ===========================
  13. When you create a database handle, you *should* specify the autocommit
  14. behaviour that you require. PDO will default to autocommit on.
  15. $dbh = new PDO("...", $user, $pass, array(PDO_ATTR_AUTOCOMMIT => true));
  16. When auto-commit is on, the driver will implicitly commit each query as it is
  17. executed. This works fine for most simple tasks but can be significantly
  18. slower when you are making a large number of udpates.
  19. $dbh = new PDO("...", $user, $pass, array(PDO_ATTR_AUTOCOMMIT => false));
  20. When auto-commit is off, you must then use $dbh->beginTransaction() to
  21. initiate a transaction. When your work is done, you then call $dbh->commit()
  22. or $dbh->rollBack() to persist or abort your changes respectively. Not all
  23. databases support transactions.
  24. You can change the auto-commit mode at run-time:
  25. $dbh->setAttribute(PDO_ATTR_AUTOCOMMIT, false);
  26. Regardless of the error handling mode set on the database handle, if the
  27. autocommit mode cannot be changed, an exception will be thrown.
  28. Some drivers will allow you to temporarily disable autocommit if you call
  29. $dbh->beginTransaction(). When you commit() or rollBack() such a transaction,
  30. the handle will switch back to autocommit mode again. If the mode could not
  31. be changed, an exception will be raised, as noted above.
  32. When the database handle is closed or destroyed (or at request end for
  33. persistent handles), the driver will implicitly rollBack(). It is your
  34. responsibility to call commit() when you are done making changes and
  35. autocommit is turned off.
  36. vim:tw=78:et