Db.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ XPoN8KX6bC4qpM5es9her1f+yUppk0Sg3JNKaS+2zGQ=
  5. *
  6. * @link http://codecu.be/framework
  7. * @copyright Copyright (c) 2015 CodeCube SRL
  8. * @license http://codecu.be/framework/license Commercial License
  9. *
  10. * @version 1.4
  11. */
  12. namespace Cube;
  13. /**
  14. * database class
  15. *
  16. * Class Db
  17. *
  18. * @package Cube
  19. */
  20. class Db
  21. {
  22. const INT_TYPE = 0;
  23. const FLOAT_TYPE = 1;
  24. const FETCH_ASSOC = 2;
  25. const FETCH_BOTH = 4;
  26. const FETCH_BOUND = 6;
  27. const FETCH_CLASS = 8;
  28. const FETCH_CLASSTYPE = 262144;
  29. const FETCH_COLUMN = 7;
  30. const FETCH_FUNC = 10;
  31. const FETCH_GROUP = 65536;
  32. const FETCH_INTO = 9;
  33. const FETCH_LAZY = 1;
  34. const FETCH_NAMED = 11;
  35. const FETCH_NUM = 3;
  36. const FETCH_OBJ = 5;
  37. const FETCH_ORI_ABS = 4;
  38. const FETCH_ORI_FIRST = 2;
  39. const FETCH_ORI_LAST = 3;
  40. const FETCH_ORI_NEXT = 0;
  41. const FETCH_ORI_PRIOR = 1;
  42. const FETCH_ORI_REL = 5;
  43. const FETCH_SERIALIZE = 524288;
  44. const FETCH_UNIQUE = 196608;
  45. const NULL_EMPTY_STRING = 1;
  46. const NULL_NATURAL = 0;
  47. const NULL_TO_STRING = null;
  48. const PARAM_BOOL = 5;
  49. const PARAM_INPUT_OUTPUT = -2147483648;
  50. const PARAM_INT = 1;
  51. const PARAM_LOB = 3;
  52. const PARAM_NULL = 0;
  53. const PARAM_STMT = 4;
  54. const PARAM_STR = 2;
  55. /**
  56. *
  57. * database factory
  58. *
  59. * @param mixed $adapter
  60. * @param array $config
  61. *
  62. * @return mixed database adapter
  63. * @throws \RuntimeException
  64. */
  65. public static function factory($adapter, $config = array())
  66. {
  67. if (class_exists($adapter)) {
  68. $dbAdapter = new $adapter($config);
  69. }
  70. else {
  71. throw new \RuntimeException(
  72. sprintf("Database adapter %s does not exist", $adapter));
  73. }
  74. return $dbAdapter;
  75. }
  76. }