<?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> |
// +----------------------------------------------------------------------+
//
// IBase_Driver is the Database driver for the InterBase database system.
//
/*!
<package name="IBase_Driver">
<class name="IBase_Query"
parent="Query"
access="public"
date="2001-05-29 11:05:37"
version="0.6">
<author name="John Luxford"
email="lux@simian.ca"
url="http://www.simian.ca/" />
<summary>IBase_Driver is the Database driver for the InterBase database system.
IBase_Query provides all of the InterBase-specific functionality
for Query objects. It is accessed through the Database class API.</summary>
<example>$q = new IBase_Query ("select * from table");
if ($q->execute ()) {
while ($row = $q->fetch ()) {
// do something with $row
}
$q->free ();
} else {
// query failed
}</example> !*/
class IBase_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="MySQL_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 IBase_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->result = ibase_query ($this->tmp_sql);
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->result) {
$info = ibase_field_info ($this->result, $num);
return $info["name"];
} else {
return 0;
}
}
/*! <method name="rows" access="public">
<summary>Returns the number of rows affected or found by the current query.
Note: Uses the ibase_num_fields() function, which does not work correctly
in PHP4.</summary>
<returns type="integer" />
</method> !*/
function rows () {
if ($this->result) {
// NOTE: IBASE_NUM_FIELDS DOES NOT RETURN CORRECT NUMBERS IN PHP4!!!
// THE DOCUMENTATION SHOWS MIXED INFO ABOUT WHETHER IT'S RETURNING
// THE NUMBER OF ROWS OR THE NUMBER OF COLUMNS IN THE RESULT SET,
// AND SHOWS EXAMPLES OF USING IT TO RETRIEVE BOTH... I SUSPECT IT'S
// THE LATTER HOWEVER.
return ibase_num_fields ($this->result);
} else {
return 0;
}
}
/*! <method name="lastid" access="public">
<summary>Returns the row ID generated by the database during the previous
SQL insert query.
Note: Not yet implemented.</summary>
<returns type="integer" />
</method> !*/
function lastid () {
/* if ($this->result) {
return mysql_insert_id ();
} else {
return 0;
} */
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) {
return ibase_fetch_object ($this->result);
} 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) {
return ibase_free_query ($this->result);
} */
}
/*! <method name="begin" access="public">
<summary>Issues an ibase_trans() statement, beginning a transaction.</summary>
</method> !*/
function begin () {
return ibase_trans ();
}
/*! <method name="commit" access="public">
<summary>Issues an ibase_commet() statement, committing the current transaction.</summary>
</method> !*/
function commit ($trans_no = "") {
return ibase_commit ($trans_no);
}
/*! <method name="rollback" access="public">
<summary>Issues an ibase_rollback() statement, rolling back the current transaction.</summary>
</method> !*/
function rollback ($trans_no = "") {
return ibase_rollback ($trans_no);
}
}
/*! </class>
<class name="IBase_Driver"
access="public"
date="2001-05-29 11:05:37"
version="0.6">
<author name="John Luxford"
email="lux@simian.ca"
url="http://www.simian.ca/" />
<summary>IBase_Driver provides all of the InterBase-specific functionality
for Database objects. It is accessed through the Database class API.</summary>
<example>$db = new IBase_Driver ("name", "host", "user", "pass", 1);
if ($db->connection) {
// connection worked
} else {
// connection failed
}</example> !*/
class IBase_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="IBase_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 IBase_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 ($this->persistent) {
$this->connection = ibase_pconnect ($this->name, $this->user, $this->pass);
} else {
$this->connection = ibase_connect ($this->name, $this->user, $this->pass);
}
}
/*! <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> !*/
?> |