Source for file db-oracle.php

Documentation is available at db-oracle.php

  1. <?php
  2. /* ******************************************************************** */
  3. /* CATALYST PHP Source Code */
  4. /* -------------------------------------------------------------------- */
  5. /* This program is free software; you can redistribute it and/or modify */
  6. /* it under the terms of the GNU General Public License as published by */
  7. /* the Free Software Foundation; either version 2 of the License, or */
  8. /* (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU General Public License for more details. */
  14. /* */
  15. /* You should have received a copy of the GNU General Public License */
  16. /* along with this program; if not, write to: */
  17. /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
  18. /* Boston, MA 02111-1307 USA */
  19. /* -------------------------------------------------------------------- */
  20. /* */
  21. /* Filename: db-oracle.php */
  22. /* Author: Paul Waite, Mark Kessell */
  23. /* Description: Definitions for ORACLE 8i database access. This was */
  24. /* written for the OCI8 interface for Php4. */
  25. /* */
  26. /* ******************************************************************** */
  27. /** @package database */* ORACLE 8 database interface
  28. * This is a database interface class. It is an impedance-matcher
  29. * between the high-level Axyl functions for accessing data, and
  30. * the specific functions suplpied by Php to access a particular
  31. * flavour of databse such as Postgres, MS-SQL Server, Sybase etc.
  32. * @package database
  33. * @access private
  34. */
  35. class db_oracle extends database {
  36. var $result;
  37. var $numrows = 0;
  38. // ....................................................................
  39. /** Constructor */
  40.  
  41. function db_oracle($name="", $user="", $passwd="", $host="", $port=1521, $enc="", $datestyle="") {
  42. $this->database($name, $user, $passwd, $host, $port, $enc, $datestyle);
  43. $this->type = "oracle";
  44. }
  45. // ....................................................................
  46. /**
  47. * Connect to the database.
  48. * @param boolean $persistent Whether to connect persistently or not
  49. * @return boolean Status true if connected successfully
  50. */
  51. function connect($persistent=NOT_PERSISTENT) {
  52. if (!$this->connected) {
  53. if ($persistent)
  54. $this->dbid = ociplogon($this->user, $this->passwd, $this->name);
  55. else
  56. $this->dbid = ocilogon($this->user, $this->passwd, $this->name);
  57. if ($this->dbid) {
  58. $this->connected = true;
  59. }
  60. }
  61. return $this->connected;
  62. }
  63. // ....................................................................
  64. /** Disconnect from the database, if connected. */
  65.  
  66. function disconnect() {
  67. if (ocilogoff($this->dbid)) {
  68. $this->connected = false;
  69. }
  70. }
  71. // ....................................................................
  72. /**
  73. * Execute a query on the connected database.
  74. * @param string $sql The SQL query to execute on the database
  75. * @return resource A database query resource ID, or false if query failed
  76. */
  77. function query($sql) {
  78. $sql = $this->convert_boolean_syntax($sql);
  79. $this->timer->restart();
  80. $rid = ociparse($this->dbid, $sql);
  81. if ($rid !== false) {
  82. $didexecute = ociexecute($rid);
  83. }
  84. $this->timer->stop();
  85. $this->executable_sql = $sql;
  86. $this->rid = $rid;
  87. $this->query_report();
  88. return ($didexecute ? $rid : false);
  89. }
  90. // ....................................................................
  91. /**
  92. * Return the number of rows returned by a SELECT query.
  93. * @param resource $rid The resource ID for the executed query
  94. * @return integer The number of rows returned by the query
  95. */
  96. function numrows($rid) {
  97. if ($rid !== false) {
  98. ociexecute($rid);
  99. }
  100. $this->numrows = ocifetchstatement($rid, $this->records);
  101. return $this->numrows;
  102. }
  103. // ....................................................................
  104. /**
  105. * Return the number of rows affected by a query.
  106. * @param resource $rid The resource ID for the executed query
  107. * @return integer The number of rows affected by the query
  108. */
  109. function affectedrows($rid) {
  110. return ocirowcount($rid);
  111. }
  112. // ....................................................................
  113. /**
  114. * Free a resource.
  115. * @param resource $rid The resource ID for the executed query
  116. */
  117. function freeresult($rid) {
  118. ocifreestatement($rid);
  119. }
  120. // ....................................................................
  121. /**
  122. * Return the last error message.
  123. * @return string The last error message which was generated
  124. */
  125. function errormessage() {
  126. return ocierror($this->dbid);
  127. }
  128. // ....................................................................
  129. /**
  130. * Return the specified row, as a standard (enumerated) array of
  131. * field values.
  132. * @param resource $rid The resource ID for the executed query
  133. * @param integer $rowno Row number (zero-based) of row to return
  134. * @return array Enumerated array of field values
  135. */
  136. function fetch_row($rid, $rowno) {
  137. if ($rid !== false) {
  138. ociexecute($rid);
  139. }
  140. if (!isset($this->result)) {
  141. $this->result = array();
  142. $row = array();
  143. while (ocifetchinto($rid, $row, OCI_NUM+OCI_RETURN_LOBS)) {
  144. $this->result[] = convert_oci_array($row);
  145. }
  146. }
  147. return $this->result[$rowno];
  148. }
  149. // ....................................................................
  150. /**
  151. * Return the specified row, as an associative array of fields
  152. * in a fieldname => value format.
  153. * @param resource $rid The resource ID for the executed query
  154. * @param integer $rowno Row number (zero-based) of row to return
  155. * @return array Associative array of field values
  156. */
  157. function fetch_array($rid, $rowno) {
  158. if ($rid !== false) {
  159. ociexecute($rid);
  160. }
  161. if (!isset($this->result)) {
  162. $this->result = array();
  163. $row = array();
  164. while (ocifetchinto($rid, $row, OCI_ASSOC+OCI_RETURN_LOBS)) {
  165. $this->result[] = convert_oci_array($row);
  166. }
  167. }
  168. return $this->result[$rowno];
  169. }
  170. function lock($tablelist, $mode) {
  171. $res = true;
  172. $tables = explode(",", $tablelist);
  173. foreach($tables as $table) {
  174. $rid = $this->query("LOCK $table IN $mode");
  175. if ($rid === false) {
  176. $res = false;
  177. }
  178. }
  179. return $res;
  180. }
  181. }
  182.  
  183. // ----------------------------------------------------------------------
  184. // UTILITY FUNCTIONS
  185.  
  186. /**
  187. * Function to convert the Oracle returned array format into the more
  188. * useful associative array format we usually deal with.
  189. * @param array $array Original Oracle formatted array of results
  190. * @return array The converted associative array of results
  191. * @access private
  192. */
  193. function convert_oci_array($array) {
  194. // converts the array's key values to lower case
  195. $temp = array();
  196. foreach ($array as $k => $v ) {
  197. $tk = strtolower($k);
  198. $temp["$tk"] = $v;
  199. }
  200. return $temp;
  201. }
  202.  
  203. // ----------------------------------------------------------------------
  204. ?>

Documentation generated by phpDocumentor 1.3.0RC3