PHP Classes

File: Oracle_Driver.php

Recommend this page to a friend!
  Classes of John Luxford  >  Database.php  >  Oracle_Driver.php  >  Download  
File: Oracle_Driver.php
Role: ???
Content type: text/plain
Description: The Oracle driver classes.
Class: Database.php
Author: By
Last change:
Date: 21 years ago
Size: 9,682 bytes
 

Contents

Class file image Download
<?php // // +----------------------------------------------------------------------+ // | Sitellite - Content Management System | // +----------------------------------------------------------------------+ // | Copyright (c) 2001 Simian Systems | // +----------------------------------------------------------------------+ // | This software is released under the Simian Open Software License. | // | Please see the accompanying file OPENLICENSE for licensing details! | // | | // | You should have received a copy of the Simian Open Software License | // | along with this program; if not, write to Simian Systems, | // | 101-314 Broadway, Winnipeg, MB, R3C 0S7, CANADA. The Simian | // | Public License is also available at the following web site | // | address: <http://www.simian.ca/license.php> | // +----------------------------------------------------------------------+ // | Authors: John Luxford <lux@simian.ca> | // +----------------------------------------------------------------------+ // // Oracle_Driver is the Database driver for the Oracle database system. // /*! <package name="Oracle_Driver"> <class name="Oracle_Query" parent="Query" access="public" date="2001-05-29 11:05:37" version="1.0"> <author name="John Luxford" email="lux@simian.ca" url="http://www.simian.ca/" /> <summary>Oracle_Driver is the Database driver for the Oracle database system. Oracle_Query provides all of the Oracle-specific functionality for Query objects. It is accessed through the Database class API.</summary> <example>$q = new Oracle_Query ("select * from table"); if ($q->execute ()) { while ($row = $q->fetch ()) { // do something with $row } $q->free (); } else { // query failed }</example> !*/ class Oracle_Query extends Query { /*! <property name="sql" access="public" type="string"> <summary>Contains the SQL query to be executed.</summary> </property> !*/ var $sql = ""; /*! <property name="result" access="public" type="resource"> <summary>Contains the result identifier for the current execution.</summary> </property> !*/ var $result = ""; /*! <property name="field" access="public" type="string"> <summary>Currently unused.</summary> </property> !*/ var $field = ""; /*! <property name="connection" access="public" type="resource"> <summary>The resource ID for the database connection to be queried.</summary> </property> !*/ var $connection = ""; /*! <method name="Oracle_Query" access="public"> <summary>Constructor method. $sql is the SQL query you wish to execute with this object. $conn is the database connection resource to be queried.</summary> <param name="sql" type="string" /> <param name="conn" type="resource" /> </method> !*/ function Oracle_Query ($sql = "", $conn = "") { $this->Query ($sql, $conn); } /*! <method name="execute" access="public"> <summary>Executes the current SQL query. $values is an array of values to substitute. The syntax for denoting bind_values in the SQL query is a double-questionmark (??). Returns the new SQL query. Note: does not modify the actual $sql property.</summary> <param name="values" type="array" /> <returns type="resource" /> </method> !*/ function execute () { // call bind_values $this->bind_values (func_get_args ()); // query the database $this->index = ora_open ($this->connection); $this->cursor = ora_parse ($this->index, $this->tmp_sql); $this->result = ora_exec ($this->cursor); return $this->result; } /*! <method name="field" access="public"> <summary>Returns the name of the specified column in the table currently being queried. $num is the column number. Note: Some database systems begin with column 0, while others with 1.</summary> <param name="num" type="integer" /> <returns type="string" /> </method> !*/ function field ($num = 0) { if ($this->cursor) { return ora_columnname ($this->cursor, $num); } else { return 0; } } /*! <method name="rows" access="public"> <summary>Returns the number of rows affected or found by the current query.</summary> <returns type="integer" /> </method> !*/ function rows () { if ($this->index) { return ora_numrows ($this->index); } else { return 0; } } /*! <method name="lastid" access="public"> <summary>Returns the row ID generated by the database during the previous SQL insert query. This method is currently not implemented and will simply return 0.</summary> <returns type="integer" /> </method> !*/ function lastid () { //if ($this->result) { //return mysql_insert_id (); //} else { return 0; //} } /*! <method name="fetch" access="public"> <summary>Returns the next row of data from the current query, always in the form of an object, with each column as its properties.</summary> <returns type="object" /> </method> !*/ function fetch () { if ($this->result) { ora_fetch_into ($this->result, &$array); for ($i = 0; $i < count ($array); $i++) { $obj->{ora_columnname ($this->cursor, $i)} = $array[$i]; } return $obj; } else { return 0; } } /*! <method name="free" access="public"> <summary>Tells the database system to let go of its data from the previous query.</summary> </method> !*/ function free () { if ($this->result) { $this->index = ''; $this->cursor = ''; $this->result = ''; return 1; } } /*! <method name="begin" access="public"> <summary>Issues a "begin" statement, beginning a transaction. Actually, this method is not used.</summary> </method> !*/ function begin () { //mysql_query ("begin"); } /*! <method name="commit" access="public"> <summary>Issues a "commit" statement, committing the current transaction. If you are using a persistent connection, this method must be called at the end of your scripts so that everything you have done is committed and not carried on.</summary> </method> !*/ function commit () { return ora_commit ($this->connection); } /*! <method name="rollback" access="public"> <summary>Issues a "rollback" statement, rolling back the current transaction.</summary> </method> !*/ function rollback () { return ora_rollback ($this->connection); } } /*! </class> <class name="Oracle_Driver" access="public" date="2001-05-29 11:05:37" version="1.0"> <author name="John Luxford" email="lux@simian.ca" url="http://www.simian.ca/" /> <summary>Oracle_Driver provides all of the Oracle-specific functionality for Database objects. It is accessed through the Database class API.</summary> <example>$db = new Oracle_Driver ("name", "host", "user", "pass", 1); if ($db->connection) { // connection worked } else { // connection failed }</example> !*/ class Oracle_Driver { /*! <property name="connection" access="public" type="resource"> <summary>Contains the database connection resource.</summary> </property> !*/ var $connection; /*! <property name="name" access="public" type="string"> <summary>Contains the name of the database being used.</summary> </property> !*/ var $name; /*! <property name="host" access="public" type="string"> <summary>Contains the name of the database host.</summary> </property> !*/ var $host; /*! <property name="user" access="public" type="string"> <summary>Contains the username used to connect to the current database.</summary> </property> !*/ var $user; /*! <property name="pass" access="public" type="string"> <summary>Contains the password used to connect to the current database.</summary> </property> !*/ var $pass; /*! <property name="persistent" access="public" type="boolean"> <summary>A 1 or 0 (true or false, and true by default), specifying whether to establish a persistent connection or not.</summary> </property> !*/ var $persistent; /*! <method name="Oracle_Driver" access="public"> <summary>Constructor method.</summary> <param name="name" type="string" /> <param name="host" type="string" /> <param name="user" type="string" /> <param name="pass" type="string" /> <param name="persistent" type="boolean" default="1" /> </method> !*/ function Oracle_Driver ($name = "", $host = "", $user = "", $pass = "", $persistent = 1) { $this->name = $name; $this->host = $host; $this->user = $user; $this->pass = $pass; $this->persistent = $persistent; $this->connect (); } /*! <method name="connect" access="public"> <summary>Establishes a connection with the database</summary> </method> !*/ function connect () { if (! empty ($this->host)) { $param1 = $this->user . '@' . $this->host; } else { $param1 = $this->user; } if ($this->persistent) { $this->connection = ora_plogon ($param1, $this->pass); } else { $this->connection = ora_logon ($param1, $this->pass); } // mysql_select_db ($this->name, $this->connection); } /*! <method name="query" access="public"> <summary>Creates and returns a Query object. $sql is the SQL query you wish to execute with this object.</summary> <param name="sql" type="string" /> <returns type="object" /> </method> !*/ function query ($sql = "") { // inherits full functionality from Database class } } /*! </class> </package> !*/ ?>