[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Pear/DB/ -> dbase.php (source)

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


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7