| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?php
- /* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
- // +----------------------------------------------------------------------+
- // | PHP Version 4 |
- // +----------------------------------------------------------------------+
- // | Copyright (c) 1997-2004 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 |
- // | license@php.net so we can mail you a copy immediately. |
- // +----------------------------------------------------------------------+
- // | Author: Tomas V.V.Cox <cox@idecnet.com> |
- // | Maintainer: Daniel Convissor <danielc@php.net> |
- // +----------------------------------------------------------------------+
- //
- // $Id: dbase.php,v 1.17 2004/02/19 18:26:10 danielc Exp $
- // XXX legend:
- // You have to compile your PHP with the --enable-dbase option
- require_once 'DB/common.php';
- /**
- * Database independent query interface definition for PHP's dbase
- * extension.
- *
- * @package DB
- * @version $Id: dbase.php,v 1.17 2004/02/19 18:26:10 danielc Exp $
- * @category Database
- * @author Stig Bakken <ssb@php.net>
- */
- class DB_dbase extends DB_common
- {
- // {{{ properties
- var $connection;
- var $phptype, $dbsyntax;
- var $prepare_tokens = array();
- var $prepare_types = array();
- var $res_row = array();
- var $result = 0;
- // }}}
- // {{{ constructor
- /**
- * DB_mysql constructor.
- *
- * @access public
- */
- function DB_dbase()
- {
- $this->DB_common();
- $this->phptype = 'dbase';
- $this->dbsyntax = 'dbase';
- $this->features = array(
- 'prepare' => false,
- 'pconnect' => false,
- 'transactions' => false,
- 'limit' => false
- );
- $this->errorcode_map = array();
- }
- // }}}
- // {{{ connect()
- function connect($dsninfo, $persistent = false)
- {
- if (!DB::assertExtension('dbase')) {
- return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
- }
- $this->dsn = $dsninfo;
- ob_start();
- $conn = dbase_open($dsninfo['database'], 0);
- $error = ob_get_contents();
- ob_end_clean();
- if (!$conn) {
- return $this->raiseError(DB_ERROR_CONNECT_FAILED, null,
- null, null, strip_tags($error));
- }
- $this->connection = $conn;
- return DB_OK;
- }
- // }}}
- // {{{ disconnect()
- function disconnect()
- {
- $ret = dbase_close($this->connection);
- $this->connection = null;
- return $ret;
- }
- // }}}
- // {{{ &query()
- function &query($query = null)
- {
- // emulate result resources
- $this->res_row[$this->result] = 0;
- $tmp =& new DB_result($this, $this->result++);
- return $tmp;
- }
- // }}}
- // {{{ fetchInto()
- /**
- * Fetch a row and insert the data into an existing array.
- *
- * Formating of the array and the data therein are configurable.
- * See DB_result::fetchInto() for more information.
- *
- * @param resource $result query result identifier
- * @param array $arr (reference) array where data from the row
- * should be placed
- * @param int $fetchmode how the resulting array should be indexed
- * @param int $rownum the row number to fetch
- *
- * @return mixed DB_OK on success, NULL when end of result set is
- * reached or on failure
- *
- * @see DB_result::fetchInto()
- * @access private
- */
- function fetchInto($result, &$arr, $fetchmode, $rownum=null)
- {
- if ($rownum === null) {
- $rownum = $this->res_row[$result]++;
- }
- if ($fetchmode & DB_FETCHMODE_ASSOC) {
- $arr = @dbase_get_record_with_names($this->connection, $rownum);
- if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
- $arr = array_change_key_case($arr, CASE_LOWER);
- }
- } else {
- $arr = @dbase_get_record($this->connection, $rownum);
- }
- if (!$arr) {
- return null;
- }
- if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
- $this->_rtrimArrayValues($arr);
- }
- if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
- $this->_convertNullArrayValuesToEmpty($arr);
- }
- return DB_OK;
- }
- // }}}
- // {{{ numCols()
- function numCols($foo)
- {
- return dbase_numfields($this->connection);
- }
- // }}}
- // {{{ numRows()
- function numRows($foo)
- {
- return dbase_numrecords($this->connection);
- }
- // }}}
- // {{{ quoteSmart()
- /**
- * Format input so it can be safely used in a query
- *
- * @param mixed $in data to be quoted
- *
- * @return mixed Submitted variable's type = returned value:
- * + null = the string <samp>NULL</samp>
- * + boolean = <samp>T</samp> if true or
- * <samp>F</samp> if false. Use the <kbd>Logical</kbd>
- * data type.
- * + integer or double = the unquoted number
- * + other (including strings and numeric strings) =
- * the data with single quotes escaped by preceeding
- * single quotes then the whole string is encapsulated
- * between single quotes
- *
- * @internal
- */
- function quoteSmart($in)
- {
- if (is_int($in) || is_double($in)) {
- return $in;
- } elseif (is_bool($in)) {
- return $in ? 'T' : 'F';
- } elseif (is_null($in)) {
- return 'NULL';
- } else {
- return "'" . $this->escapeSimple($in) . "'";
- }
- }
- // }}}
- }
- /*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- */
- ?>
|