dbase.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. // $Id: dbase.php,v 1.17 2004/02/19 18:26:10 danielc Exp $
  21. // XXX legend:
  22. // You have to compile your PHP with the --enable-dbase option
  23. require_once 'DB/common.php';
  24. /**
  25. * Database independent query interface definition for PHP's dbase
  26. * extension.
  27. *
  28. * @package DB
  29. * @version $Id: dbase.php,v 1.17 2004/02/19 18:26:10 danielc Exp $
  30. * @category Database
  31. * @author Stig Bakken <ssb@php.net>
  32. */
  33. class DB_dbase extends DB_common
  34. {
  35. // {{{ properties
  36. var $connection;
  37. var $phptype, $dbsyntax;
  38. var $prepare_tokens = array();
  39. var $prepare_types = array();
  40. var $res_row = array();
  41. var $result = 0;
  42. // }}}
  43. // {{{ constructor
  44. /**
  45. * DB_mysql constructor.
  46. *
  47. * @access public
  48. */
  49. function DB_dbase()
  50. {
  51. $this->DB_common();
  52. $this->phptype = 'dbase';
  53. $this->dbsyntax = 'dbase';
  54. $this->features = array(
  55. 'prepare' => false,
  56. 'pconnect' => false,
  57. 'transactions' => false,
  58. 'limit' => false
  59. );
  60. $this->errorcode_map = array();
  61. }
  62. // }}}
  63. // {{{ connect()
  64. function connect($dsninfo, $persistent = false)
  65. {
  66. if (!DB::assertExtension('dbase')) {
  67. return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
  68. }
  69. $this->dsn = $dsninfo;
  70. ob_start();
  71. $conn = dbase_open($dsninfo['database'], 0);
  72. $error = ob_get_contents();
  73. ob_end_clean();
  74. if (!$conn) {
  75. return $this->raiseError(DB_ERROR_CONNECT_FAILED, null,
  76. null, null, strip_tags($error));
  77. }
  78. $this->connection = $conn;
  79. return DB_OK;
  80. }
  81. // }}}
  82. // {{{ disconnect()
  83. function disconnect()
  84. {
  85. $ret = dbase_close($this->connection);
  86. $this->connection = null;
  87. return $ret;
  88. }
  89. // }}}
  90. // {{{ &query()
  91. function &query($query = null)
  92. {
  93. // emulate result resources
  94. $this->res_row[$this->result] = 0;
  95. $tmp =& new DB_result($this, $this->result++);
  96. return $tmp;
  97. }
  98. // }}}
  99. // {{{ fetchInto()
  100. /**
  101. * Fetch a row and insert the data into an existing array.
  102. *
  103. * Formating of the array and the data therein are configurable.
  104. * See DB_result::fetchInto() for more information.
  105. *
  106. * @param resource $result query result identifier
  107. * @param array $arr (reference) array where data from the row
  108. * should be placed
  109. * @param int $fetchmode how the resulting array should be indexed
  110. * @param int $rownum the row number to fetch
  111. *
  112. * @return mixed DB_OK on success, NULL when end of result set is
  113. * reached or on failure
  114. *
  115. * @see DB_result::fetchInto()
  116. * @access private
  117. */
  118. function fetchInto($result, &$arr, $fetchmode, $rownum=null)
  119. {
  120. if ($rownum === null) {
  121. $rownum = $this->res_row[$result]++;
  122. }
  123. if ($fetchmode & DB_FETCHMODE_ASSOC) {
  124. $arr = @dbase_get_record_with_names($this->connection, $rownum);
  125. if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
  126. $arr = array_change_key_case($arr, CASE_LOWER);
  127. }
  128. } else {
  129. $arr = @dbase_get_record($this->connection, $rownum);
  130. }
  131. if (!$arr) {
  132. return null;
  133. }
  134. if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
  135. $this->_rtrimArrayValues($arr);
  136. }
  137. if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
  138. $this->_convertNullArrayValuesToEmpty($arr);
  139. }
  140. return DB_OK;
  141. }
  142. // }}}
  143. // {{{ numCols()
  144. function numCols($foo)
  145. {
  146. return dbase_numfields($this->connection);
  147. }
  148. // }}}
  149. // {{{ numRows()
  150. function numRows($foo)
  151. {
  152. return dbase_numrecords($this->connection);
  153. }
  154. // }}}
  155. // {{{ quoteSmart()
  156. /**
  157. * Format input so it can be safely used in a query
  158. *
  159. * @param mixed $in data to be quoted
  160. *
  161. * @return mixed Submitted variable's type = returned value:
  162. * + null = the string <samp>NULL</samp>
  163. * + boolean = <samp>T</samp> if true or
  164. * <samp>F</samp> if false. Use the <kbd>Logical</kbd>
  165. * data type.
  166. * + integer or double = the unquoted number
  167. * + other (including strings and numeric strings) =
  168. * the data with single quotes escaped by preceeding
  169. * single quotes then the whole string is encapsulated
  170. * between single quotes
  171. *
  172. * @internal
  173. */
  174. function quoteSmart($in)
  175. {
  176. if (is_int($in) || is_double($in)) {
  177. return $in;
  178. } elseif (is_bool($in)) {
  179. return $in ? 'T' : 'F';
  180. } elseif (is_null($in)) {
  181. return 'NULL';
  182. } else {
  183. return "'" . $this->escapeSimple($in) . "'";
  184. }
  185. }
  186. // }}}
  187. }
  188. /*
  189. * Local variables:
  190. * tab-width: 4
  191. * c-basic-offset: 4
  192. * End:
  193. */
  194. ?>