README 1.9 KB

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