cvs: php4 /pear/DB ibase.php sybase.php
| From: | Stig Bakken | Date: | Mon, 24 Jul 2000 08:02:15 +0000 |
| Subject: | cvs: php4 /pear/DB ibase.php sybase.php | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-884@lists.php.net to get a copy of this message | ||
ssb Mon Jul 24 01:02:15 2000 EDT
Added files:
/php4/pear/DB sybase.php ibase.php
Log:
@Added Sterling Hughes's sybase and ibase DB backends
Index: php4/pear/DB/sybase.php
+++ php4/pear/DB/sybase.php
<?php
//
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 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_0.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 |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Sterling Hughes <sterling@designmultimedia.com> |
// | |
// +----------------------------------------------------------------------+
//
// Database independent query interface definition for PHP's Sybase
// extension.
//
if (!empty($GLOBALS['USED_PACKAGES']['DB/sybase'])) return;
$GLOBALS['USED_PACKAGES']['DB/sybase'] = true;
if (empty($GLOBALS['USED_PACKAGES']['DB/common'])) {
include("DB/common.php");
}
class DB_sybase extends DB_common {
var $connection;
var $phptype, $dbsyntax;
var $prepare_tokens = array();
var $prepare_types = array();
function DB_sybase() {
$this->phptype = 'sybase';
$this->dbsyntax = 'sybase';
$this->features = array(
'prepare' => false,
'pconnect' => true,
'transactions' => false
);
}
function connect ( $dsn, $persistant=false ) {
if(is_array($dsn)) {
$dsninfo = &$dsn;
} else {
$dsninfo = DB::parseDSN($dsn);
}
if (!$dsninfo || !$dsninfo['phptype']) {
return DB_ERROR;
}
$dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
$connect_function = $persistent ? 'sybase_pconnect' : 'sybase_connect';
$conn = $dbhost ? $connect_function($dbhost) : false;
$dsninfo['database'] && sybase_select_db($dsninfo['database'], $conn);
$this->connection = $conn;
return DB_OK;
}
function disconnect() {
return sybase_close($this->connection);
}
function &query( $stmt ) {
$result = sybase_query($stmt, $this->connection);
if (!$result) {
return DB_ERROR;
}
// Determine which queries that should return data, and which
// should return an error code only.
if (preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $stmt)) {
$resultObj = new DB_result($this, $result);
return $resultObj;
} else {
return DB_OK;
}
}
function simpleQuery($stmt) {
$result = sybase_query($stmt, $this->connection);
if (!$result) {
return DB_ERROR;
}
// Determine which queries that should return data, and which
// should return an error code only.
return preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $stmt) ? $result : DB_OK;
}
function &fetchRow($result, $getmode=DB_GETMODE_DEFAULT) {
$row = ($getmode & DB_GETMODE_ASSOC) ? sybase_fetch_array($result) :
sybase_fetch_row($result);
if (!$row) {
return DB_ERROR;
}
return $row;
}
function fetchInto($result, &$ar, $getmode=DB_GETMODE_DEFAULT) {
$ar = ($getmode & DB_GETMODE_ASSOC) ? sybase_fetch_array($result) : sybase_fetch_row($result);
if (!$ar) {
return DB_ERROR;
}
return DB_OK;
}
function freeResult($result) {
if (is_resource($result)) {
return sybase_free_result($result);
}
if (!isset($this->prepare_tokens[$result])) {
return false;
}
unset($this->prepare_tokens[$result]);
unset($this->prepare_types[$result]);
return true;
}
function numCols($result) {
$cols = sybase_num_fields($result);
if (!$cols) {
return DB_ERROR;
}
return $cols;
}
function prepare($query) {
$tokens = split('[\&\?]', $query);
$token = 0;
$types = array();
for ($i = 0; $i < strlen($query); $i++) {
switch ($query[$i]) {
case '?':
$types[$token++] = DB_PARAM_SCALAR;
break;
case '&':
$types[$token++] = DB_PARAM_OPAQUE;
break;
}
}
$this->prepare_tokens[] = &$tokens;
end($this->prepare_tokens);
$k = key($this->prepare_tokens);
$this->prepare_types[$k] = $types;
return $k;
}
function execute($stmt, $data = false) {
$realquery = $this->execute_emulate_query($stmt, $data);
$result = sybase_query($realquery, $this->connection);
if (!$result) {
return DB_ERROR;
}
return preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $realquery) ? $result : DB_OK;
}
function autoCommit($onoff=false) {
return DB_ERROR_NOT_CAPABLE;
}
function commit() {
return DB_ERROR_NOT_CAPABLE;
}
function rollback() {
return DB_ERROR_NOT_CAPABLE;
}
}
?>
Index: php4/pear/DB/ibase.php
+++ php4/pear/DB/ibase.php
<?php
//
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 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_0.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 |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Sterling Hughes <sterling@designmultimedia.com> |
// | |
// +----------------------------------------------------------------------+
//
// Database independent query interface definition for PHP's Interbase
// extension.
//
if (!empty($GLOBALS['USED_PACKAGES']['DB/ibase'])) return;
$GLOBALS['USED_PACKAGES']['DB/ibase'] = true;
if (empty($GLOBALS['USED_PACKAGES']['DB/common'])) {
include("DB/common.php");
}
class DB_ibase extends DB_common {
var $connection;
var $phptype, $dbsyntax;
var $prepare_tokens = array();
var $prepare_types = array();
function DB_ibase() {
$this->phptype = 'ibase';
$this->dbsyntax = 'ibase';
$this->features = array(
'prepare' => true,
'pconnect' => true,
'transactions' => true
);
}
function connect ( $dsn, $persistant=false ) {
if(is_array($dsn)) {
$dsninfo = &$dsn;
} else {
$dsninfo = DB::parseDSN($dsn);
}
if (!$dsninfo || !$dsninfo['phptype']) {
return DB_ERROR;
}
$user = $dsninfo['username'];
$pw = $dsninfo['password'];
$dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
$connect_function = $persistent ? 'ibase_pconnect' : 'ibase_connect';
if ($dbhost && $user && $pw) {
$conn = $connect_function($dbhost, $user, $pw);
} elseif ($dbhost && $user) {
$conn = $connect_function($dbhost, $user);
} elseif ($dbhost) {
$conn = $connect_function($dbhost);
} else {
return DB_ERROR;
}
$this->connection = $conn;
return DB_OK;
}
function disconnect() {
return ibase_close($this->connection);
}
function &query( $stmt ) {
$result = ibase_query($stmt, $this->connection); // arg order are currently wrong but will be
correct by PHP4
if (!$result) {
return DB_ERROR;
}
// Determine which queries that should return data, and which
// should return an error code only.
if (preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $stmt)) {
$resultObj = new DB_result($this, $result);
return $resultObj;
} else {
return DB_OK;
}
}
function simpleQuery($stmt) {
$result = ibase_query($stmt, $this->connection);
if (!$result) {
return DB_ERROR;
}
// Determine which queries that should return data, and which
// should return an error code only.
return preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $stmt) ? $result : DB_OK;
}
function &fetchRow($result, $getmode=DB_GETMODE_DEFAULT) {
if ($getmode & DB_GETMODE_ASSOC) {
return DB_ERROR_NOT_CAPABLE;
} else {
$row = ibase_fetch_row($result);
}
if (!$row) {
return DB_ERROR;
}
return $row;
}
function fetchInto($result, &$ar, $getmode=DB_GETMODE_DEFAULT) {
if ($getmode & DB_GETMODE_ASSOC) {
return DB_ERROR_NOT_CAPABLE;
} else {
$ar = ibase_fetch_row($result);
}
if (!$ar) {
return DB_ERROR;
}
return DB_OK;
}
function freeResult() {
return DB_ERROR_NOT_CAPABLE;
}
function freeQuery($query) {
ibase_free_query($query);
return true;
}
function numCols($result) {
$cols = ibase_num_fields($result);
if (!$cols) {
return DB_ERROR;
}
return $cols;
}
function prepare($query) {
return ibase_prepare($query);
}
function execute($stmt, $data = false) {
$result = ibase_execute($stmt, $data);
if (!$result) {
return DB_ERROR;
}
return preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $stmt) ? $result : DB_OK;
}
function autoCommit($onoff=false) {
return DB_ERROR_NOT_CAPABLE;
}
function commit() {
return ibase_commit($this->connection);
}
function rollback($trans_number) {
return ibase_rollback($this->connection,$trans_number);
}
function transactionInit($trans_args=0) {
return $trans_args ? ibase_trans($trans_args, $this->connection) : ibase_trans();
}
}
?>