PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/thirdparty/pear/DB/dbase.php

https://github.com/sfsergey/knowledgetree
PHP | 225 lines | 102 code | 27 blank | 96 comment | 15 complexity | 8d3f62a355db8888245c129dbd775114 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, GPL-3.0
  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$
  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$
  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. $ini = ini_get('track_errors');
  71. if ($ini) {
  72. $conn = @dbase_open($dsninfo['database'], 0);
  73. } else {
  74. ini_set('track_errors', 1);
  75. $conn = @dbase_open($dsninfo['database'], 0);
  76. ini_set('track_errors', $ini);
  77. }
  78. if (!$conn) {
  79. return $this->raiseError(DB_ERROR_CONNECT_FAILED, null,
  80. null, null, strip_tags($php_errormsg));
  81. }
  82. $this->connection = $conn;
  83. return DB_OK;
  84. }
  85. // }}}
  86. // {{{ disconnect()
  87. function disconnect()
  88. {
  89. $ret = @dbase_close($this->connection);
  90. $this->connection = null;
  91. return $ret;
  92. }
  93. // }}}
  94. // {{{ &query()
  95. function &query($query = null)
  96. {
  97. // emulate result resources
  98. $this->res_row[(int)$this->result] = 0;
  99. $tmp =& new DB_result($this, $this->result++);
  100. return $tmp;
  101. }
  102. // }}}
  103. // {{{ fetchInto()
  104. /**
  105. * Fetch a row and insert the data into an existing array.
  106. *
  107. * Formating of the array and the data therein are configurable.
  108. * See DB_result::fetchInto() for more information.
  109. *
  110. * @param resource $result query result identifier
  111. * @param array $arr (reference) array where data from the row
  112. * should be placed
  113. * @param int $fetchmode how the resulting array should be indexed
  114. * @param int $rownum the row number to fetch
  115. *
  116. * @return mixed DB_OK on success, null when end of result set is
  117. * reached or on failure
  118. *
  119. * @see DB_result::fetchInto()
  120. * @access private
  121. */
  122. function fetchInto($result, &$arr, $fetchmode, $rownum=null)
  123. {
  124. if ($rownum === null) {
  125. $rownum = $this->res_row[(int)$result]++;
  126. }
  127. if ($fetchmode & DB_FETCHMODE_ASSOC) {
  128. $arr = @dbase_get_record_with_names($this->connection, $rownum);
  129. if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
  130. $arr = array_change_key_case($arr, CASE_LOWER);
  131. }
  132. } else {
  133. $arr = @dbase_get_record($this->connection, $rownum);
  134. }
  135. if (!$arr) {
  136. return null;
  137. }
  138. if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
  139. $this->_rtrimArrayValues($arr);
  140. }
  141. if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
  142. $this->_convertNullArrayValuesToEmpty($arr);
  143. }
  144. return DB_OK;
  145. }
  146. // }}}
  147. // {{{ numCols()
  148. function numCols($foo)
  149. {
  150. return @dbase_numfields($this->connection);
  151. }
  152. // }}}
  153. // {{{ numRows()
  154. function numRows($foo)
  155. {
  156. return @dbase_numrecords($this->connection);
  157. }
  158. // }}}
  159. // {{{ quoteSmart()
  160. /**
  161. * Format input so it can be safely used in a query
  162. *
  163. * @param mixed $in data to be quoted
  164. *
  165. * @return mixed Submitted variable's type = returned value:
  166. * + null = the string <samp>NULL</samp>
  167. * + boolean = <samp>T</samp> if true or
  168. * <samp>F</samp> if false. Use the <kbd>Logical</kbd>
  169. * data type.
  170. * + integer or double = the unquoted number
  171. * + other (including strings and numeric strings) =
  172. * the data with single quotes escaped by preceeding
  173. * single quotes then the whole string is encapsulated
  174. * between single quotes
  175. *
  176. * @internal
  177. */
  178. function quoteSmart($in)
  179. {
  180. if (is_int($in) || is_double($in)) {
  181. return $in;
  182. } elseif (is_bool($in)) {
  183. return $in ? 'T' : 'F';
  184. } elseif (is_null($in)) {
  185. return 'NULL';
  186. } else {
  187. return "'" . $this->escapeSimple($in) . "'";
  188. }
  189. }
  190. // }}}
  191. }
  192. /*
  193. * Local variables:
  194. * tab-width: 4
  195. * c-basic-offset: 4
  196. * End:
  197. */
  198. ?>