jon Fri Mar 23 11:26:55 2001 EDT
Added files:
/php4/pear/DB ifx.php
Modified files:
/php4/pear/DB MAINTAINERS
Log:
Adding an Informix (ifx) database implementation.
Submitted by: "Tomas V.V.Cox" <[EMAIL PROTECTED]>
Index: php4/pear/DB/MAINTAINERS
diff -u php4/pear/DB/MAINTAINERS:1.3 php4/pear/DB/MAINTAINERS:1.4
--- php4/pear/DB/MAINTAINERS:1.3 Wed Dec 13 06:41:04 2000
+++ php4/pear/DB/MAINTAINERS Fri Mar 23 11:26:55 2001
@@ -9,3 +9,4 @@
pgsql : Rui Hirokawa <[EMAIL PROTECTED]>
Stig Bakken <[EMAIL PROTECTED]>
sybase :
+ifx : Tomas V.V.Cox <[EMAIL PROTECTED]>
Index: php4/pear/DB/ifx.php
+++ php4/pear/DB/ifx.php
<?php
//
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2001 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | [EMAIL PROTECTED] so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Tomas V.V.Cox <[EMAIL PROTECTED]> |
// +----------------------------------------------------------------------+
//
// Database independent query interface definition for PHP's Informix
// extension.
//
// Legend:
// For more info on Informix errors see:
// http://www.informix.com/answers/english/ierrors.htm
//
require_once 'DB/common.php';
class DB_ifx extends DB_common
{
var $connection;
var $numrows;
var $row;
var $affected = 0;
var $fetchmode = DB_FETCHMODE_ASSOC; /* Default fetch mode */
function DB_ifx()
{
$this->phptype = 'ifx';
$this->dbsyntax = 'ifx';
$this->features = array(
'prepare' => false,
'pconnect' => true,
'transactions' => false
);
$this->errorcode_map = array();
}
/**
* Connect to a database and log in as the specified user.
*
* @param $dsn the data source name (see DB::parseDSN for syntax)
* @param $persistent (optional) whether the connection should
* be persistent
*
* @return int DB_OK on success, a DB error code on failure
*/
function connect(&$dsn, $persistent = false)
{
$dsninfo = DB::parseDSN($dsn);
$dbhost = $dsninfo['hostspec'] ? '@' . $dsninfo['hostspec'] : '';
$dbname = $dsninfo['database'] ? $dsninfo['database'] . $dbhost : '';
$user = $dsninfo['username'] ? $dsninfo['username'] : '';
$pw = $dsninfo['password'] ? $dsninfo['password'] : '';
$connect_function = $persistent ? 'ifx_pconnect' : 'ifx_connect';
$this->connection = @$connect_function($dbname, $user, $pw);
if ($this->connection == false) {
return $this->ifxraiseError();
}
return DB_OK;
}
/**
* Log out and disconnect from the database.
*
* @return bool TRUE on success, FALSE if not connected.
*/
function disconnect()
{
return @ifx_close($this->connection);
}
/**
* Send a query to Informix and return the results as a
* Informix resource identifier.
*
* @param $query the SQL query
*
* @return int returns a valid Informix result for successful SELECT
* queries, DB_OK for other successful queries. A DB error code
* is returned on failure.
*/
function simpleQuery($query)
{
$this->last_query = $query;
// the scroll is needed for fetching absolute row numbers
// in a select query result
$cursor = (preg_match('/(SELECT)/i', $query)) ? IFX_SCROLL : null;
if (!$result = @ifx_prepare($query, $this->connection, $cursor)) {
return $this->ifxraiseError();
}
if (!@ifx_do($result)) {
return $this->ifxraiseError();
}
$this->affected = ifx_affected_rows ($result);
// Determine which queries that should return data, and which
// should return an error code only.
if (preg_match('/(SELECT)/i', $query)) {
return $result;
} else {
return DB_OK;
}
}
/**
* Gets the number of rows affected by the last query.
* if the last query was a select, returns an _estimate_ value.
*
* @return number of rows affected by the last query
*/
function affectedRows()
{
return $this->affected;
}
/**
* Fetch a row and return as array.
*
* @param $result Informix result identifier
* @param $fetchmode how the resulting array should be indexed
* @param $rownum the row number to fetch
*
* @return int an array on success, a DB error code on failure, NULL
* if there is no more data
*/
function &fetchRow($result, $fetchmode, $rownum=null)
{
$rownum = (!empty($rownum) && ($rownum > 0)) ? $rownum : null;
if (!$row = @ifx_fetch_row($result, $rownum)) {
return NULL;
}
switch ($fetchmode){
case DB_FETCHMODE_ASSOC:
return $row;
case DB_FETCHMODE_ORDERED:
$i=0;
foreach ($row as $key => $val) {
$order[$i++] = $val;
}
return $order;
default:
return $this->raiseError(DB_ERROR_UNSUPPORTED);
}
}
function numRows($result)
{
return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
/**
* Get the number of columns in a result set.
*
* @param $result Informix result identifier
*
* @return int the number of columns per row in $result
*/
function numCols($result)
{
if (!$cols = @ifx_num_fields($result)) {
return $this->ifxraiseError();
}
return $cols;
}
/**
* Free the internal resources associated with $result.
*
* @param $result Informix result identifier
*
* @return bool TRUE on success, DB_error on error
*/
function freeResult($result)
{
if (!@ifx_free_result($result)) {
return $this->ifxraiseError();
}
return true;
}
function fetchInto($res, &$arr, $mode)
{
return $this->raiseError(DB_ERROR_UNSUPPORTED);
}
function ifxraiseError($errno = null)
{
if ($errno == null) {
$errno = $this->errorCode();
}
return $this->raiseError($errno, false, false, false,
$this->errorNative());
}
/**
* Map native error codes to DB's portable ones. Requires that
* the DB implementation's constructor fills in the $errorcode_map
* property.
*
* @return int a portable DB error code, or DB_ERROR if this DB
* implementation has no mapping for the given error code.
*/
function errorCode()
{
if (ereg('SQLCODE=(.*)]', ifx_error(), $match)) {
$code = $match[1];
$codes = array(
'-201' => DB_ERROR_SYNTAX,
'-206' => DB_ERROR_NOSUCHTABLE,
'-217' => DB_ERROR_NOSUCHFIELD,
'-329' => DB_ERROR_NODBSELECTED,
'-1204' => DB_ERROR_INVALID_DATE,
'-1205' => DB_ERROR_INVALID_DATE,
'-1206' => DB_ERROR_INVALID_DATE,
'-1209' => DB_ERROR_INVALID_DATE,
'-1210' => DB_ERROR_INVALID_DATE,
'-1212' => DB_ERROR_INVALID_DATE
);
if (isset($codes[$code])) {
return $codes[$code];
}
}
return DB_ERROR;
}
/**
* Get the native error message of the last error (if any) that
* occured on the current connection.
*
* @return int native Informix error code
*/
function errorNative()
{
return ifx_error() . ' ' . ifx_errormsg();
}
}
?>
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]