cvs: php4 /pear DB.php TODO /pear/DB common.php ibase.php msql.php mssql.php mysql.php oci8.php odbc.php pgsql.php storage.php sybase.php
/pear/DB/tests fetchmodes.inc /pear/DB/tests/mysql 001.phpt 002.phpt mktable.inc skipif.inc
| From: | Stig Bakken | Date: | Tue, 12 Sep 2000 00:27:51 +0000 |
| Subject: | cvs: php4 /pear DB.php TODO /pear/DB common.php ibase.php msql.php mssql.php mysql.php oci8.php odbc.php pgsql.php storage.php sybase.php /pear/DB/tests fetchmodes.inc /pear/DB/tests/mysql 001.phpt 002.phpt mktable.inc skipif.inc |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1721@lists.php.net to get a copy of this message | ||
ssb Mon Sep 11 17:27:51 2000 EDT
Added files:
/php4/pear/DB/tests fetchmodes.inc
/php4/pear/DB/tests/mysql 001.phpt 002.phpt mktable.inc skipif.inc
Modified files:
/php4/pear DB.php TODO
/php4/pear/DB common.php ibase.php msql.php mssql.php mysql.php
oci8.php odbc.php pgsql.php storage.php sybase.php
Log:
@PEAR: renamed DB_GETMODE_* to DB_FETCHMODE_*, added setFetchMode()
@ in DB_common to set the default mode, added some MySQL tests (Stig)
Index: php4/pear/DB.php
diff -u php4/pear/DB.php:1.30 php4/pear/DB.php:1.31
--- php4/pear/DB.php:1.30 Mon Aug 28 16:09:36 2000
+++ php4/pear/DB.php Mon Sep 11 17:27:50 2000
@@ -17,7 +17,7 @@
// | |
// +----------------------------------------------------------------------+
//
-// $Id: DB.php,v 1.30 2000/08/28 23:09:36 ssb Exp $
+// $Id: DB.php,v 1.31 2000/09/12 00:27:50 ssb Exp $
//
// Database independent query interface.
//
@@ -94,31 +94,32 @@
define("DB_BINMODE_CONVERT", 3);
+
+/**
+ * This is a special constant that tells DB the user hasn't specified
+ * any particular get mode, so the default should be used.
+ */
+define('DB_FETCHMODE_DEFAULT', 0);
/**
* Column data indexed by numbers, ordered from 0 and up
*/
-define('DB_GETMODE_ORDERED', 1);
+define('DB_FETCHMODE_ORDERED', 1);
/**
* Column data indexed by column names
*/
-define('DB_GETMODE_ASSOC', 2);
+define('DB_FETCHMODE_ASSOC', 2);
/**
* For multi-dimensional results: normally the first level of arrays
* is the row number, and the second level indexed by column number or name.
- * DB_GETMODE_FLIPPED switches this order, so the first level of arrays
+ * DB_FETCHMODE_FLIPPED switches this order, so the first level of arrays
* is the column name, and the second level the row number.
- */
-define('DB_GETMODE_FLIPPED', 4);
-
-
-/**
- * This constant DB's default get mode. It is possible to override by
- * defining in your scripts before including DB.
*/
-if (!defined('DB_GETMODE_DEFAULT')) {
- define('DB_GETMODE_DEFAULT', DB_GETMODE_ORDERED);
-}
+define('DB_FETCHMODE_FLIPPED', 4);
+/* for compatibility */
+define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED);
+define('DB_GETMODE_ASSOC', DB_FETCHMODE_ASSOC);
+define('DB_GETMODE_FLIPPED', DB_FETCHMODE_FLIPPED);
/**
* The main "DB" class is simply a container class with some static
@@ -141,7 +142,7 @@
* connections, the object returned is an instance of this
* class.
*
- * @version 1.00
+ * @version 2
* @author Stig Bakken <ssb@fast.no>
* @since PHP 4.0
*/
@@ -199,7 +200,7 @@
* @return int the DB API version number
*/
function apiVersion() {
- return 1;
+ return 2;
}
/**
@@ -405,8 +406,11 @@
* Fetch and return a row of data.
* @return array a row of data, or false on error
*/
- function fetchRow($getmode = DB_GETMODE_DEFAULT) {
- return $this->dbh->fetchRow($this->result, $getmode);
+ function fetchRow($fetchmode = DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->dbh->fetchmode;
+ }
+ return $this->dbh->fetchRow($this->result, $fetchmode);
}
/**
@@ -415,8 +419,11 @@
* @param $arr reference to data array
* @return int error code
*/
- function fetchInto(&$arr, $getmode = DB_GETMODE_DEFAULT) {
- return $this->dbh->fetchInto($this->result, $arr, $getmode);
+ function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->dbh->fetchmode;
+ }
+ return $this->dbh->fetchInto($this->result, $arr, $fetchmode);
}
/**
@@ -441,6 +448,14 @@
return true;
}
}
+
+/*
+ * DB_Error TODO:
+ *
+ * - needs a way of storing queries (useful for debugging query syntax
+ * errors)
+ *
+ */
/**
* DB_Error implements a class for reporting portable database error
Index: php4/pear/TODO
diff -u php4/pear/TODO:1.1 php4/pear/TODO:1.2
--- php4/pear/TODO:1.1 Mon Jul 24 06:32:50 2000
+++ php4/pear/TODO Mon Sep 11 17:27:50 2000
@@ -1,4 +1,4 @@
-TODO file for PEAR. Last modified $Date: 2000/07/24 13:32:50 $ by $Author: ssb $
+TODO file for PEAR. Last modified $Date: 2000/09/12 00:27:50 $ by $Author: ssb $
Legend:
@@ -15,5 +15,6 @@
Bundled PEAR packages:
-- make regression tests for DB
+W ssb make regression tests for DB
+- make DB_Error store queries
W uw implement Javadoc -> phpdoc/DocBook conversion
Index: php4/pear/DB/common.php
diff -u php4/pear/DB/common.php:1.18 php4/pear/DB/common.php:1.19
--- php4/pear/DB/common.php:1.18 Fri Sep 8 19:39:56 2000
+++ php4/pear/DB/common.php Mon Sep 11 17:27:50 2000
@@ -20,14 +20,6 @@
// Base class for DB implementations.
//
-//
-// XXX legend:
-//
-// XXX ERRORMSG: Needs a better way of dealing with errors.
-
-if (!empty($GLOBALS['USED_PACKAGES']['DB/common'])) return;
-$GLOBALS['USED_PACKAGES']['DB/common'] = true;
-
/**
* DB_common is a base class for DB implementations, and should be
* inherited by all such.
@@ -66,6 +58,7 @@
function DB_common() {
$this->features = array();
$this->errorcode_map = array();
+ $this->fetchmode = DB_FETCHMODE_ORDERED;
}
// }}}
@@ -141,6 +134,10 @@
// }}}
// {{{ raiseError()
+ /**
+ * This method is called by DB to generate an error.
+ *
+ */
function &raiseError($code = DB_ERROR, $mode = false, $level = false) {
if (!$mode) {
$mode = $this->error_mode;
@@ -162,25 +159,51 @@
// }}}
// {{{ setErrorHandling()
- function setErrorHandling($mode, $level = false) {
+ /**
+ * Sets how errors generated by this DB object should be handled.
+ *
+ * @param $mode int
+ * one of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
+ * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE or
+ * PEAR_ERROR_CALLBACK.
+ *
+ * @param $options mixed
+ * Ignored unless $mode is PEAR_ERROR_TRIGGER or
+ * PEAR_ERROR_CALLBACK. When $mode is PEAR_ERROR_TRIGGER,
+ * this parameter is expected to be an integer among
+ * E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR. When
+ * $mode is PEAR_ERROR_CALLBACK, this parameter is expected
+ * to be the callback function or method. A callback
+ * function is a string with the name of the function, a
+ * callback method is an array of two elements: the element
+ * at index 0 is an object, and the element at index 1 is
+ * the name of the method to call in the object.
+ *
+ * @see PEAR_ERROR_RETURN
+ * @see PEAR_ERROR_PRINT
+ * @see PEAR_ERROR_TRIGGER
+ * @see PEAR_ERROR_DIE
+ * @see PEAR_ERROR_CALLBACK
+ */
+ function setErrorHandling($mode, $options = false) {
switch ($mode) {
case PEAR_ERROR_RETURN:
case PEAR_ERROR_PRINT:
case PEAR_ERROR_TRIGGER:
case PEAR_ERROR_DIE:
$this->error_mode = $mode;
- if (!$level) {
+ if (!$options) {
$this->error_level = E_USER_NOTICE;
} else {
- $this->error_level = $level;
+ $this->error_level = $options;
}
break;
case PEAR_ERROR_CALLBACK:
$this->error_mode = $mode;
- if (is_string($level) ||
- (is_array($level) && sizeof($level) == 2 &&
- is_object($level[0]) && is_string($level[1]))) {
- $this->error_callback = $level;
+ if (is_string($options) ||
+ (is_array($options) && sizeof($options) == 2 &&
+ is_object($options[0]) && is_string($options[1]))) {
+ $this->error_callback = $options;
} else {
trigger_error(E_USER_WARNING, "invalid error callback");
}
@@ -193,7 +216,32 @@
}
// }}}
+ // {{{ setFetchMode()
+
+ /**
+ * Sets which fetch mode should be used by default on queries
+ * on this connection.
+ *
+ * @param $fetchmode int DB_FETCHMODE_ORDERED or
+ * DB_FETCHMODE_ASSOC, possibly bit-wise OR'ed with
+ * DB_FETCHMODE_FLIPPED.
+ *
+ * @see DB_FETCHMODE_ORDERED
+ * @see DB_FETCHMODE_ASSOC
+ * @see DB_FETCHMODE_FLIPPED
+ */
+ function setFetchMode($fetchmode) {
+ switch ($fetchmode) {
+ case DB_FETCHMODE_ORDERED:
+ case DB_FETCHMODE_ASSOC:
+ $this->fetchmode = $fetchmode;
+ break;
+ default:
+ return $this->raiseError("invalid get mode");
+ }
+ }
+ // }}}
// {{{ prepare()
/**
@@ -317,7 +365,7 @@
if (DB::isError($res)) {
return $res;
}
- $row = $this->fetchRow($res, DB_GETMODE_ORDERED);
+ $row = $this->fetchRow($res, DB_FETCHMODE_ORDERED);
if (DB::isError($row)) {
return $row;
}
@@ -340,7 +388,10 @@
* @return array the first row of results as an array indexed from
* 0, or a DB error code.
*/
- function &getRow($query, $getmode = DB_GETMODE_DEFAULT, $params = array()) {
+ function &getRow($query, $fetchmode = DB_FETCHMODE_DEFAULT, $params = array()) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
if (sizeof($params) > 0) {
$sth = $this->prepare($query);
if (DB::isError($sth)) {
@@ -353,7 +404,7 @@
if (DB::isError($res)) {
return $res;
}
- $row = $this->fetchRow($res, $getmode);
+ $row = $this->fetchRow($res, $fetchmode);
if (DB::isError($row)) {
return $row;
}
@@ -392,9 +443,9 @@
if (DB::isError($res)) {
return $res;
}
- $getmode = is_int($col) ? DB_GETMODE_ORDERED : DB_GETMODE_ASSOC;
+ $fetchmode = is_int($col) ? DB_FETCHMODE_ORDERED : DB_FETCHMODE_ASSOC;
$ret = array();
- while ($row = $this->fetchRow($res, $getmode)) {
+ while ($row = $this->fetchRow($res, $fetchmode)) {
if (DB::isError($row)) {
$ret = $row;
break;
@@ -508,7 +559,10 @@
*
* @return array an indexed array, or a DB error
*/
- function &getAll($query, $getmode = DB_GETMODE_DEFAULT, $params = array()) {
+ function &getAll($query, $fetchmode = DB_FETCHMODE_DEFAULT, $params = array()) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
if (sizeof($params) > 0) {
$sth = $this->prepare($query);
if (DB::isError($sth)) {
@@ -522,7 +576,7 @@
return $res;
}
$results = array();
- while (($row = $this->fetchRow($res, $getmode)) && !DB::isError($row)) {
+ while (($row = $this->fetchRow($res, $fetchmode)) && !DB::isError($row)) {
foreach ($row as $key => $val) {
$results[$key][] = $val;
}
Index: php4/pear/DB/ibase.php
diff -u php4/pear/DB/ibase.php:1.6 php4/pear/DB/ibase.php:1.7
--- php4/pear/DB/ibase.php:1.6 Fri Sep 8 19:39:56 2000
+++ php4/pear/DB/ibase.php Mon Sep 11 17:27:50 2000
@@ -16,13 +16,13 @@
// | Authors: Sterling Hughes <sterling@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: ibase.php,v 1.6 2000/09/09 02:39:56 ssb Exp $
+// $Id: ibase.php,v 1.7 2000/09/12 00:27:50 ssb Exp $
//
// Database independent query interface definition for PHP's Interbase
// extension.
//
-include_once 'DB/common.php';
+require_once 'DB/common.php';
class DB_ibase extends DB_common {
@@ -96,8 +96,11 @@
return preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $stmt) ? $result : DB_OK;
}
- function &fetchRow($result, $getmode=DB_GETMODE_DEFAULT) {
- if ($getmode & DB_GETMODE_ASSOC) {
+ function &fetchRow($result, $fetchmode=DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
+ if ($fetchmode & DB_FETCHMODE_ASSOC) {
$row = (array)ibase_fetch_object($result);
} else {
$row = ibase_fetch_row($result);
@@ -108,8 +111,11 @@
return $row;
}
- function fetchInto($result, &$ar, $getmode=DB_GETMODE_DEFAULT) {
- if ($getmode & DB_GETMODE_ASSOC) {
+ function fetchInto($result, &$ar, $fetchmode=DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
+ if ($fetchmode & DB_FETCHMODE_ASSOC) {
return $this->raiseError(DB_ERROR_NOT_CAPABLE);
} else {
$ar = ibase_fetch_row($result);
Index: php4/pear/DB/msql.php
diff -u php4/pear/DB/msql.php:1.7 php4/pear/DB/msql.php:1.8
--- php4/pear/DB/msql.php:1.7 Fri Sep 8 19:39:56 2000
+++ php4/pear/DB/msql.php Mon Sep 11 17:27:50 2000
@@ -16,13 +16,13 @@
// | Authors: Sterling Hughes <sterling@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: msql.php,v 1.7 2000/09/09 02:39:56 ssb Exp $
+// $Id: msql.php,v 1.8 2000/09/12 00:27:50 ssb Exp $
//
// Database independent query interface definition for PHP's Mini-SQL
// extension.
//
-include_once 'DB/common.php';
+require_once 'DB/common.php';
class DB_msql extends DB_common {
@@ -104,8 +104,11 @@
}
}
- function &fetchRow($result, $getmode=DB_GETMODE_DEFAULT) {
- if ($getmode & DB_GETMODE_ASSOC) {
+ function &fetchRow($result, $fetchmode=DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
+ if ($fetchmode & DB_FETCHMODE_ASSOC) {
$row = @msql_fetch_array($result, MSQL_ASSOC);
} else {
$row = @msql_fetch_row($result);
@@ -116,8 +119,11 @@
return $row;
}
- function fetchInto($result, &$ar, $getmode=DB_GETMODE_DEFAULT) {
- if ($getmode & DB_GETMODE_ASSOC) {
+ function fetchInto($result, &$ar, $fetchmode=DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
+ if ($fetchmode & DB_FETCHMODE_ASSOC) {
$ar = @msql_fetch_array($result, MSQL_ASSOC);
} else {
$ar = @msql_fetch_row($result);
Index: php4/pear/DB/mssql.php
diff -u php4/pear/DB/mssql.php:1.10 php4/pear/DB/mssql.php:1.11
--- php4/pear/DB/mssql.php:1.10 Fri Sep 8 19:39:56 2000
+++ php4/pear/DB/mssql.php Mon Sep 11 17:27:50 2000
@@ -16,13 +16,13 @@
// | Authors: Sterling Hughes <sterling@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: mssql.php,v 1.10 2000/09/09 02:39:56 ssb Exp $
+// $Id: mssql.php,v 1.11 2000/09/12 00:27:50 ssb Exp $
//
// Database independent query interface definition for PHP's Microsoft SQL Server
// extension.
//
-include_once 'DB/common.php';
+require_once 'DB/common.php';
class DB_mssql extends DB_common {
@@ -104,8 +104,11 @@
}
}
- function &fetchRow($result, $getmode=DB_GETMODE_DEFAULT) {
- if ($getmode & DB_GETMODE_ASSOC) {
+ function &fetchRow($result, $fetchmode=DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
+ if ($fetchmode & DB_FETCHMODE_ASSOC) {
$row = @mssql_fetch_array($result);
} else {
$row = @mssql_fetch_row($result);
@@ -116,8 +119,11 @@
return $row;
}
- function fetchInto($result, &$ar, $getmode=DB_GETMODE_DEFAULT) {
- if ($getmode & DB_GETMODE_ASSOC) {
+ function fetchInto($result, &$ar, $fetchmode=DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
+ if ($fetchmode & DB_FETCHMODE_ASSOC) {
$ar = @mssql_fetch_array($result);
} else {
$ar = @mssql_fetch_row($result);
Index: php4/pear/DB/mysql.php
diff -u php4/pear/DB/mysql.php:1.23 php4/pear/DB/mysql.php:1.24
--- php4/pear/DB/mysql.php:1.23 Fri Sep 8 19:39:56 2000
+++ php4/pear/DB/mysql.php Mon Sep 11 17:27:50 2000
@@ -196,15 +196,18 @@
* Fetch a row and return as array.
*
* @param $result MySQL result identifier
- * @param $getmode how the resulting array should be indexed
+ * @param $fetchmode how the resulting array should be indexed
*
* @access public
*
* @return int an array on success, a DB error on failure, NULL
* if there is no more data
*/
- function &fetchRow($result, $getmode = DB_GETMODE_DEFAULT) {
- if ($getmode & DB_GETMODE_ASSOC) {
+ function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
+ if ($fetchmode & DB_FETCHMODE_ASSOC) {
$row = mysql_fetch_array($result, MYSQL_ASSOC);
} else {
$row = mysql_fetch_row($result);
@@ -227,14 +230,17 @@
*
* @param $result MySQL result identifier
* @param $arr (reference) array where data from the row is stored
- * @param $getmode how the array data should be indexed
+ * @param $fetchmode how the array data should be indexed
*
* @access public
*
* @return int DB_OK on success, a DB error on failure
*/
- function fetchInto($result, &$arr, $getmode = DB_GETMODE_DEFAULT) {
- if ($getmode & DB_GETMODE_ASSOC) {
+ function fetchInto($result, &$arr, $fetchmode = DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
+ if ($fetchmode & DB_FETCHMODE_ASSOC) {
$arr = mysql_fetch_array($result, MYSQL_ASSOC);
} else {
$arr = mysql_fetch_row($result);
Index: php4/pear/DB/oci8.php
diff -u php4/pear/DB/oci8.php:1.7 php4/pear/DB/oci8.php:1.8
--- php4/pear/DB/oci8.php:1.7 Fri Sep 8 19:39:56 2000
+++ php4/pear/DB/oci8.php Mon Sep 11 17:27:50 2000
@@ -28,7 +28,7 @@
//
-include_once 'DB/common.php';
+require_once 'DB/common.php';
class DB_oci8 extends DB_common {
// {{{ properties
@@ -189,13 +189,16 @@
* Fetch a row and return as array.
*
* @param $result oci8 result identifier
- * @param $getmode how the resulting array should be indexed
+ * @param $fetchmode how the resulting array should be indexed
*
* @return int an array on success, a DB error code on failure, NULL
* if there is no more data
*/
- function &fetchRow($result, $getmode = DB_GETMODE_DEFAULT) {
- if ($getmode & DB_GETMODE_ASSOC) {
+ function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
+ if ($fetchmode & DB_FETCHMODE_ASSOC) {
$moredata=OCIFetchInto($result,$row,OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS);
} else {
$moredata=OCIFetchInto($result,$row,OCI_RETURN_NULLS+OCI_RETURN_LOBS);
@@ -217,12 +220,15 @@
*
* @param $result oci8 result identifier
* @param $arr (reference) array where data from the row is stored
- * @param $getmode how the array data should be indexed
+ * @param $fetchmode how the array data should be indexed
*
* @return int DB_OK on success, a DB error code on failure
*/
- function fetchInto($result, &$arr, $getmode = DB_GETMODE_DEFAULT) {
- if ($getmode & DB_GETMODE_ASSOC) {
+ function fetchInto($result, &$arr, $fetchmode = DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
+ if ($fetchmode & DB_FETCHMODE_ASSOC) {
$moredata=OCIFetchInto($result,$arr,OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS);
} else {
$moredata=OCIFetchInto($result,$arr,OCI_RETURN_NULLS+OCI_RETURN_LOBS);
Index: php4/pear/DB/odbc.php
diff -u php4/pear/DB/odbc.php:1.14 php4/pear/DB/odbc.php:1.15
--- php4/pear/DB/odbc.php:1.14 Fri Sep 8 19:39:56 2000
+++ php4/pear/DB/odbc.php Mon Sep 11 17:27:50 2000
@@ -31,7 +31,7 @@
// a reference.
//
-include_once 'DB/common.php';
+require_once 'DB/common.php';
class DB_odbc extends DB_common {
// {{{ properties
Index: php4/pear/DB/pgsql.php
diff -u php4/pear/DB/pgsql.php:1.11 php4/pear/DB/pgsql.php:1.12
--- php4/pear/DB/pgsql.php:1.11 Fri Sep 8 19:39:56 2000
+++ php4/pear/DB/pgsql.php Mon Sep 11 17:27:50 2000
@@ -46,7 +46,7 @@
// be registered here.
//
-include_once 'DB/common.php';
+require_once 'DB/common.php';
class DB_pgsql extends DB_common {
// {{{ properties
@@ -200,16 +200,19 @@
* Fetch a row and return as array.
*
* @param $result PostgreSQL result identifier
- * @param $getmode how the resulting array should be indexed
+ * @param $fetchmode how the resulting array should be indexed
*
* @return int an array on success, a DB error code on failure, NULL
* if there is no more data
*/
- function &fetchRow($result, $getmode = DB_GETMODE_DEFAULT) {
+ function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
if ($this->row[$result]>=$this->numrows[$result]){
return NULL;
}
- if ($getmode & DB_GETMODE_ASSOC) {
+ if ($fetchmode & DB_FETCHMODE_ASSOC) {
$row = pg_fetch_array($result, $this->row[$result]);
} else {
$row = pg_fetch_row($result, $this->row[$result]);
@@ -233,15 +236,18 @@
*
* @param $result PostgreSQL result identifier
* @param $arr (reference) array where data from the row is stored
- * @param $getmode how the array data should be indexed
+ * @param $fetchmode how the array data should be indexed
*
* @return int DB_OK on success, a DB error code on failure
*/
- function fetchInto($result, &$arr, $getmode = DB_GETMODE_DEFAULT) {
+ function fetchInto($result, &$arr, $fetchmode = DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
if ($this->row[$result]>=$this->numrows[$result]){
return NULL;
}
- if ($getmode & DB_GETMODE_ASSOC) {
+ if ($fetchmode & DB_FETCHMODE_ASSOC) {
$arr = pg_fetch_array($result, $this->row[$result]);
} else {
$arr = pg_fetch_row($result, $this->row[$result]);
Index: php4/pear/DB/storage.php
diff -u php4/pear/DB/storage.php:1.8 php4/pear/DB/storage.php:1.9
--- php4/pear/DB/storage.php:1.8 Thu Sep 7 09:36:22 2000
+++ php4/pear/DB/storage.php Mon Sep 11 17:27:50 2000
@@ -90,7 +90,7 @@
if (DB::isError($sth)) {
return $sth;
}
- while ($row = $sth->fetchRow(DB_GETMODE_ASSOC)) {
+ while ($row = $sth->fetchRow(DB_FETCHMODE_ASSOC)) {
reset($row);
while (list($key, $value) = each($row)) {
$this->_properties[$key] = true;
@@ -200,7 +200,7 @@
}
$this->_properties = array();
}
- $rowdata = $this->_dbh->getRow($query, DB_GETMODE_ASSOC, $params);
+ $rowdata = $this->_dbh->getRow($query, DB_FETCHMODE_ASSOC, $params);
if (DB::isError($rowdata)) {
return $rowdata;
}
Index: php4/pear/DB/sybase.php
diff -u php4/pear/DB/sybase.php:1.6 php4/pear/DB/sybase.php:1.7
--- php4/pear/DB/sybase.php:1.6 Fri Sep 8 19:39:56 2000
+++ php4/pear/DB/sybase.php Mon Sep 11 17:27:50 2000
@@ -16,13 +16,13 @@
// | Authors: Sterling Hughes <sterling@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: sybase.php,v 1.6 2000/09/09 02:39:56 ssb Exp $
+// $Id: sybase.php,v 1.7 2000/09/12 00:27:50 ssb Exp $
//
// Database independent query interface definition for PHP's Sybase
// extension.
//
-include_once 'DB/common.php';
+require_once 'DB/common.php';
class DB_sybase extends DB_common {
@@ -87,16 +87,22 @@
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);
+ function &fetchRow($result, $fetchmode=DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
+ $row = ($fetchmode & DB_FETCHMODE_ASSOC) ? @sybase_fetch_array($result) :
@sybase_fetch_row($result);
if (!$row) {
return $this->raiseError();
}
return $row;
}
- function fetchInto($result, &$ar, $getmode=DB_GETMODE_DEFAULT) {
- $ar = ($getmode & DB_GETMODE_ASSOC) ? @sybase_fetch_array($result) :
@sybase_fetch_row($result);
+ function fetchInto($result, &$ar, $fetchmode=DB_FETCHMODE_DEFAULT) {
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
+ $ar = ($fetchmode & DB_FETCHMODE_ASSOC) ? @sybase_fetch_array($result) :
@sybase_fetch_row($result);
if (!$ar) {
return $this->raiseError();
}
@@ -165,4 +171,11 @@
return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
?>
Index: php4/pear/DB/tests/fetchmodes.inc
+++ php4/pear/DB/tests/fetchmodes.inc
<?php
$dbh->setErrorHandling(PEAR_ERROR_DIE);
// testing default default
$sth = $dbh->query("SELECT * FROM phptest");
$row = $sth->fetchRow();
//var_dump($row);
print implode(" ", array_keys($row))."\n";
// testing ordered default
$dbh->setFetchMode(DB_FETCHMODE_ORDERED);
$sth = $dbh->query("SELECT * FROM phptest");
$row = $sth->fetchRow();
//var_dump($row);
print implode(" ", array_keys($row))."\n";
// testing assoc default
$dbh->setFetchMode(DB_FETCHMODE_ASSOC);
$sth = $dbh->query("SELECT * FROM phptest");
$row = $sth->fetchRow();
//var_dump($row);
print implode(" ", array_keys($row))."\n";
// testing ordered default with assoc specified
$dbh->setFetchMode(DB_FETCHMODE_ORDERED);
$sth = $dbh->query("SELECT * FROM phptest");
$row = $sth->fetchRow(DB_FETCHMODE_ASSOC);
//var_dump($row);
print implode(" ", array_keys($row))."\n";
// testing assoc default with ordered specified
$dbh->setFetchMode(DB_FETCHMODE_ASSOC);
$sth = $dbh->query("SELECT * FROM phptest");
$row = $sth->fetchRow(DB_FETCHMODE_ORDERED);
//var_dump($row);
print implode(" ", array_keys($row))."\n";
?>
Index: php4/pear/DB/tests/mysql/001.phpt
+++ php4/pear/DB/tests/mysql/001.phpt
--TEST--
MySQL DB::connect
--SKIPIF--
<?php include("skipif.inc"); ?>
--FILE--
<?php
require_once "DB.php";
$dbh = DB::connect("mysql://localhost/test");
if (is_object($dbh)) {
print "\$dbh is an object\n";
}
if (is_resource($dbh->connection)) {
print "\$dbh is connected\n";
}
?>
--EXPECT--
$dbh is an object
$dbh is connected
Index: php4/pear/DB/tests/mysql/002.phpt
+++ php4/pear/DB/tests/mysql/002.phpt
--TEST--
MySQL DB fetch modes
--SKIPIF--
<?php include("skipif.inc"); ?>
--FILE--
<?php
require_once "DB.php";
include("mktable.inc");
include("../fetchmodes.inc");
?>
--EXPECT--
0 1 2 3
0 1 2 3
a b c d
a b c d
0 1 2 3
Index: php4/pear/DB/tests/mysql/mktable.inc
+++ php4/pear/DB/tests/mysql/mktable.inc
<?php
$dbh = DB::connect("mysql://localhost/test");
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
$dbh->query("DROP TABLE phptest");
$dbh->setErrorHandling(PEAR_ERROR_TRIGGER);
$dbh->query("CREATE TABLE phptest (a INTEGER, b VARCHAR(40), c TEXT, d DATE)");
$dbh->query("INSERT INTO phptest VALUES(42, 'bing', 'This is a test',
'1999-11-21')");
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
?>
Index: php4/pear/DB/tests/mysql/skipif.inc
+++ php4/pear/DB/tests/mysql/skipif.inc
<?php
// This script prints "skip" unless:
// * the mysql extension is built-in or loadable, AND
// * there is a database called "test" accessible
// with no username/password, AND
// * we have create/drop privileges on the entire "test"
// database
if (!extension_loaded("mysql")) {
$dlext = (substr(PHP_OS, 0, 3) == "WIN") ? ".dll" : ".so";
@dl("mysql$dlext");
}
if (!extension_loaded("mysql")) {
die("skip\n");
}
$conn = @mysql_connect("localhost");
if (!is_resource($conn)) {
die("skip\n");
}
if (!mysql_select_db("test", $conn)) {
die("skip\n");
}
?>