PHP Classes

File: ODBC_Driver.php

Recommend this page to a friend!
  Classes of John Luxford  >  Database.php  >  ODBC_Driver.php  >  Download  
File: ODBC_Driver.php
Role: ???
Content type: text/plain
Description: The ODBC driver classes.
Class: Database.php
Author: By
Last change:
Date: 21 years ago
Size: 9,307 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> | // +----------------------------------------------------------------------+ // // ODBC_Driver is the Database driver for accessing ODBC databases. // /*! <package name="ODBC_Driver"> <class name="ODBC_Query" parent="Query" access="public" date="2001-05-29 11:05:37" version="0.8"> <author name="John Luxford" email="lux@simian.ca" url="http://www.simian.ca/" /> <summary>ODBC_Driver is the Database driver for accessing ODBC databases. ODBC_Query provides all of the ODBC-specific functionality for Query objects. It is accessed through the Database class API.</summary> <example>$q = new ODBC_Query ("select * from table"); if ($q->execute ()) { while ($row = $q->fetch ()) { // do something with $row } $q->free (); } else { // query failed }</example> !*/ class ODBC_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="ODBC_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 ODBC_Query ($sql = "", $connection) { $this->Query ($sql, $connection); } /*! <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 = odbc_prepare ($this->connection, $this->tmp_sql); return odbc_execute ($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: ODBC begins with column 1, instead of 0.</summary> <param name="num" type="integer" /> <returns type="string" /> </method> !*/ function field ($num = 1) { if ($this->result) { return odbc_field_name ($this->result, $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->result) { return odbc_num_rows ($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 odbc_insert_id (); // as far as i can see, there's no function like this... } */ 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) { if (odbc_fetch_row ($this->result)) { for ($i = 1; $i < odbc_num_fields ($this->result); $i++) { $obj->{odbc_field_name ($this->result, $i)} = odbc_result ($this->result, $i); } return $obj; } else { return 0; } } 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 odbc_free_result ($this->result); } } /*! <method name="begin" access="public"> <summary>Issues an odbc_autocommit(conn, 0) statement, beginning a transaction.</summary> </method> !*/ function begin () { return odbc_autocommit ($this->connection, 0); } /*! <method name="commit" access="public"> <summary>Issues an odbc_commit() statement, committing the current transaction.</summary> </method> !*/ function commit () { return odbc_commit ($this->connection); } /*! <method name="rollback" access="public"> <summary>Issues an odbc_rollback() statement, rolling back the current transaction.</summary> </method> !*/ function rollback () { return odbc_rollback ($this->connection); } } /*! </class> <class name="ODBC_Driver" access="public" date="2001-05-29 11:05:37" version="0.8"> <author name="John Luxford" email="lux@simian.ca" url="http://www.simian.ca/" /> <summary>ODBC_Driver provides all of the ODBC-specific functionality for Database objects. It is accessed through the Database class API.</summary> <example>$db = new ODBC_Driver ("name", "host", "user", "pass", 1); if ($db->connection) { // connection worked } else { // connection failed }</example> !*/ class ODBC_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="ODBC_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 ODBC_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 = odbc_pconnect ($this->name, $this->user, $this->pass); } else { $this->connection = odbc_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> !*/ ?>