PageRenderTime 49ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Framework/DB/ADODB.php

https://github.com/shupp/Framework
PHP | 99 lines | 45 code | 9 blank | 45 comment | 5 complexity | d9043d52850a377ceee8281b791c68f6 MD5 | raw file
  1. <?php
  2. /**
  3. * Framework_DB_ADODB
  4. *
  5. * Framework Driver for ADODB or ADODBLite
  6. *
  7. * PHP Version 5.1
  8. *
  9. * @package Framework
  10. * @subpackage Framework_DB
  11. * @author Bill Shupp <hostmaster@shupp.org>
  12. * @copyright 2008 Bill Shupp
  13. * @uses Framework_DB_Common
  14. * @license BSD http://www.opensource.org/licenses/bsd-license.php
  15. * @link http://adodb.sourceforge.net/
  16. * @link http://adodblite.sourceforge.net/
  17. */
  18. require_once 'Framework/DB/Common.php';
  19. /**
  20. * Framework_DB_ADODB
  21. *
  22. * Framework Driver for ADODB or ADODBLite
  23. *
  24. * @package Framework
  25. * @subpackage Framework_DB
  26. * @author Bill Shupp <hostmaster@shupp.org>
  27. * @author Joe Stump <joe@joestump.net>
  28. * @copyright 2008 Bill Shupp
  29. * @uses Framework_DB_Common
  30. * @license BSD http://www.opensource.org/licenses/bsd-license.php
  31. * @link http://adodb.sourceforge.net/
  32. * @link http://adodblite.sourceforge.net/
  33. */
  34. class Framework_DB_ADODB extends Framework_DB_Common
  35. {
  36. /**
  37. * Create a singleton of ADODB or ADODBLite; This driver works for
  38. * both. Just specify the correct directory in
  39. * config->db->options->adodbDir.
  40. * The directory in which adodbDir resides in must be in your
  41. * include_path.
  42. *
  43. * @access public
  44. * @throws Framework_DB_Exception on failure
  45. * @return object Instance of ADODB[Lite] connected to the DB
  46. */
  47. public function singleton()
  48. {
  49. if (!is_null(parent::$db) &&
  50. parent::$db instanceof ADOConnection) {
  51. return parent::$db;
  52. }
  53. // Manually include files, ADODB does not follow naming conventions
  54. if (empty($this->options->adodbDir)) {
  55. throw new Framework_DB_Exception(
  56. 'Error: you must set $config->db->options->adodbDir'
  57. );
  58. }
  59. $path = (string)$this->options->adodbDir . DIRECTORY_SEPARATOR;
  60. if ((!include_once $path . 'adodb-exceptions.inc.php') ||
  61. (!include_once $path . 'adodb.inc.php')) {
  62. throw new Framework_DB_Exception(
  63. 'Error: could not include ADODB files'
  64. );
  65. }
  66. // Connect
  67. try {
  68. parent::$db = ADONewConnection($this->dsn);
  69. } catch (Exception $error) {
  70. throw new Framework_DB_Exception(
  71. $error->getMessage(), $error->getCode()
  72. );
  73. }
  74. // Fetch Modes
  75. $fetchModes = array(
  76. 'ADODB_FETCH_DEFAULT' => ADODB_FETCH_DEFAULT,
  77. 'ADODB_FETCH_NUM' => ADODB_FETCH_NUM,
  78. 'ADODB_FETCH_ASSOC' => ADODB_FETCH_ASSOC,
  79. 'ADODB_FETCH_BOTH' => ADODB_FETCH_BOTH
  80. );
  81. $fetchMode = ADODB_FETCH_ASSOC;
  82. if (isset($this->options->fetchMode)&&
  83. isset($fetchModes[(string)$this->options->fetchMode])) {
  84. $fetchMode = $fetchModes[(string)$this->options->fetchMode];
  85. }
  86. parent::$db->SetFetchMode($fetchMode);
  87. return parent::$db;
  88. }
  89. }
  90. ?>