PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/db/oracle.php

https://github.com/MilkZoft/zan
PHP | 128 lines | 128 code | 0 blank | 0 comment | 1 complexity | 8e6c6ac9cc50f67fc71ab6fb2209132a MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. if (!defined("ACCESS")) {
  3. die("Error: You don't have permission to access here...");
  4. }
  5. class ZP_Oracle_Db extends ZP_Load
  6. {
  7. private static $connection;
  8. private $SQL;
  9. public function connect()
  10. {
  11. if (is_null(self::$connection)) {
  12. self::$connection = oci_connect(DB_HOST, DB_USER, DB_PWD .":". DB_PORT ."/". DB_DATABASE);
  13. }
  14. return self::$connection;
  15. }
  16. public function commit()
  17. {
  18. return oci_commit(self::$connection);
  19. }
  20. public function rollBack()
  21. {
  22. return oci_rollback(self::$connection);
  23. }
  24. public function query($SQL)
  25. {
  26. if ($SQL !== "") {
  27. $query = oci_parse(self::$connection, $SQL);
  28. $this->query = oci_execute($query);
  29. }
  30. return ($this->query) ? $this->query : false;
  31. }
  32. public function insert($table, $fields, $values)
  33. {
  34. if (!$table or !$fields or !$values) {
  35. return false;
  36. }
  37. $query = "INSERT INTO $table ($fields) VALUES ($values)";
  38. return ($this->query($query)) ? true : false;
  39. }
  40. public function delete($table, $ID, $primaryKey)
  41. {
  42. if (!$table or !$ID or !$primaryKey) {
  43. return false;
  44. }
  45. $query = "DELETE FROM $table WHERE $primaryKey = '$ID'";
  46. return ($this->query($query)) ? true : false;
  47. }
  48. public function deleteBy($table, $field, $value, $limit = "LIMIT 1")
  49. {
  50. if (!$table or !$field or !$value) {
  51. return false;
  52. }
  53. if ($limit > 1) {
  54. $limit = "LIMIT $limit";
  55. }
  56. $query = "DELETE FROM $table WHERE $field = '$value' $limit";
  57. return ($this->query($query)) ? true : false;
  58. }
  59. public function deleteBySQL($table, $SQL)
  60. {
  61. if (!$table or !$SQL) {
  62. return false;
  63. }
  64. $query = "DELETE FROM $table WHERE $SQL";
  65. return ($this->query($query)) ? true : false;
  66. }
  67. public function update($table, $values, $ID, $primaryKey)
  68. {
  69. if (!$table or !$values or !$ID or !$primaryKey) {
  70. return false;
  71. }
  72. $query = "UPDATE $table SET $values WHERE $primaryKey = '$ID'";
  73. return ($this->query($query)) ? true : false;
  74. }
  75. public function updateBySQL($table, $values)
  76. {
  77. if (!$table or !$values) {
  78. return false;
  79. }
  80. $query = "UPDATE $table SET $values";
  81. return ($this->query($query)) ? true : false;
  82. }
  83. public function fetch($type)
  84. {
  85. return (!$this->query) ? false : oci_fetch_assoc($this->query);
  86. }
  87. public function rows()
  88. {
  89. return (!$this->query) ? false : (int) oci_num_rows($this->query);
  90. }
  91. public function insertID()
  92. {
  93. return 0;
  94. }
  95. public function free()
  96. {
  97. return (!$this->query) ? false : oci_free_statement($this->query);
  98. }
  99. public function close()
  100. {
  101. return (!self::$connection) ? false : oci_close(self::$connection);
  102. }
  103. }