]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/pear/DB/dbase.php
Remove svn:keywords
[SourceForge/phpwiki.git] / lib / pear / DB / dbase.php
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
3 // +----------------------------------------------------------------------+
4 // | PHP Version 4                                                        |
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2004 The PHP Group                                |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.02 of the PHP license,      |
9 // | that is bundled with this package in the file LICENSE, and is        |
10 // | available at through the world-wide-web at                           |
11 // | http://www.php.net/license/2_02.txt.                                 |
12 // | If you did not receive a copy of the PHP license and are unable to   |
13 // | obtain it through the world-wide-web, please send a note to          |
14 // | license@php.net so we can mail you a copy immediately.               |
15 // +----------------------------------------------------------------------+
16 // | Author: Tomas V.V.Cox <cox@idecnet.com>                              |
17 // | Maintainer: Daniel Convissor <danielc@php.net>                       |
18 // +----------------------------------------------------------------------+
19
20 // XXX legend:
21 //  You have to compile your PHP with the --enable-dbase option
22
23 require_once 'DB/common.php';
24
25 /**
26  * Database independent query interface definition for PHP's dbase
27  * extension.
28  *
29  * @package  DB
30  * @version  
31  * @category Database
32  * @author   Stig Bakken <ssb@php.net>
33  */
34 class DB_dbase extends DB_common
35 {
36     // {{{ properties
37
38     var $connection;
39     var $phptype, $dbsyntax;
40     var $prepare_tokens = array();
41     var $prepare_types = array();
42     var $res_row = array();
43     var $result = 0;
44
45     // }}}
46     // {{{ constructor
47
48     /**
49      * DB_mysql constructor.
50      *
51      * @access public
52      */
53     function DB_dbase()
54     {
55         $this->DB_common();
56         $this->phptype = 'dbase';
57         $this->dbsyntax = 'dbase';
58         $this->features = array(
59             'prepare'       => false,
60             'pconnect'      => false,
61             'transactions'  => false,
62             'limit'         => false
63         );
64         $this->errorcode_map = array();
65     }
66
67     // }}}
68     // {{{ connect()
69
70     function connect($dsninfo, $persistent = false)
71     {
72         if (!DB::assertExtension('dbase')) {
73             return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
74         }
75         $this->dsn = $dsninfo;
76         ob_start();
77         $conn  = @dbase_open($dsninfo['database'], 0);
78         $error = ob_get_contents();
79         ob_end_clean();
80         if (!$conn) {
81             return $this->raiseError(DB_ERROR_CONNECT_FAILED, null,
82                                      null, null, strip_tags($error));
83         }
84         $this->connection = $conn;
85         return DB_OK;
86     }
87
88     // }}}
89     // {{{ disconnect()
90
91     function disconnect()
92     {
93         $ret = @dbase_close($this->connection);
94         $this->connection = null;
95         return $ret;
96     }
97
98     // }}}
99     // {{{ &query()
100
101     function &query($query = null)
102     {
103         // emulate result resources
104         $this->res_row[$this->result] = 0;
105         $tmp =& new DB_result($this, $this->result++);
106         return $tmp;
107     }
108
109     // }}}
110     // {{{ fetchInto()
111
112     /**
113      * Fetch a row and insert the data into an existing array.
114      *
115      * Formating of the array and the data therein are configurable.
116      * See DB_result::fetchInto() for more information.
117      *
118      * @param resource $result query result identifier
119      * @param array    $arr    (reference) array where data from the row
120      *                            should be placed
121      * @param int $fetchmode how the resulting array should be indexed
122      * @param int $rownum    the row number to fetch
123      *
124      * @return mixed DB_OK on success, null when end of result set is
125      *               reached or on failure
126      *
127      * @see DB_result::fetchInto()
128      * @access private
129      */
130     function fetchInto($result, &$arr, $fetchmode, $rownum=null)
131     {
132         if ($rownum === null) {
133             $rownum = $this->res_row[$result]++;
134         }
135         if ($fetchmode & DB_FETCHMODE_ASSOC) {
136             $arr = @dbase_get_record_with_names($this->connection, $rownum);
137             if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
138                 $arr = array_change_key_case($arr, CASE_LOWER);
139             }
140         } else {
141             $arr = @dbase_get_record($this->connection, $rownum);
142         }
143         if (!$arr) {
144             return null;
145         }
146         if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
147             $this->_rtrimArrayValues($arr);
148         }
149         if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
150             $this->_convertNullArrayValuesToEmpty($arr);
151         }
152         return DB_OK;
153     }
154
155     // }}}
156     // {{{ numCols()
157
158     function numCols($foo)
159     {
160         return @dbase_numfields($this->connection);
161     }
162
163     // }}}
164     // {{{ numRows()
165
166     function numRows($foo)
167     {
168         return @dbase_numrecords($this->connection);
169     }
170
171     // }}}
172     // {{{ quoteSmart()
173
174     /**
175      * Format input so it can be safely used in a query
176      *
177      * @param mixed $in data to be quoted
178      *
179      * @return mixed Submitted variable's type = returned value:
180      *               + null = the string <samp>NULL</samp>
181      *               + boolean = <samp>T</samp> if true or
182      *                 <samp>F</samp> if false.  Use the <kbd>Logical</kbd>
183      *                 data type.
184      *               + integer or double = the unquoted number
185      *               + other (including strings and numeric strings) =
186      *                 the data with single quotes escaped by preceeding
187      *                 single quotes then the whole string is encapsulated
188      *                 between single quotes
189      *
190      * @internal
191      */
192     function quoteSmart($in)
193     {
194         if (is_int($in) || is_double($in)) {
195             return $in;
196         } elseif (is_bool($in)) {
197             return $in ? 'T' : 'F';
198         } elseif (is_null($in)) {
199             return 'NULL';
200         } else {
201             return "'" . $this->escapeSimple($in) . "'";
202         }
203     }
204
205     // }}}
206
207 }
208
209 /*
210  * Local variables:
211  * tab-width: 4
212  * c-basic-offset: 4
213  * End:
214  */
215
216 ?>