]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - extlib/DB/dbase.php
[ROUTES] Allow accept-header specification during router creation
[quix0rs-gnu-social.git] / extlib / DB / dbase.php
index 17750cd5d22b839c27e65f3f0b29ba9c3806ab01..f72540d8941fbd76de2e374f420aef27353527af 100644 (file)
@@ -27,7 +27,8 @@
 /**
  * Obtain the DB_common class so it can be extended from
  */
-require_once 'DB/common.php';
+//require_once 'DB/common.php';
+require_once 'common.php';
 
 /**
  * The methods PEAR DB uses to interact with PHP's dbase extension
@@ -52,13 +53,13 @@ class DB_dbase extends DB_common
      * The DB driver type (mysql, oci8, odbc, etc.)
      * @var string
      */
-    var $phptype = 'dbase';
+    public $phptype = 'dbase';
 
     /**
      * The database syntax variant to be used (db2, access, etc.), if any
      * @var string
      */
-    var $dbsyntax = 'dbase';
+    public $dbsyntax = 'dbase';
 
     /**
      * The capabilities of this DB implementation
@@ -73,41 +74,40 @@ class DB_dbase extends DB_common
      *
      * @var array
      */
-    var $features = array(
-        'limit'         => false,
-        'new_link'      => false,
-        'numrows'       => true,
-        'pconnect'      => false,
-        'prepare'       => false,
-        'ssl'           => false,
-        'transactions'  => false,
+    public $features = array(
+        'limit' => false,
+        'new_link' => false,
+        'numrows' => true,
+        'pconnect' => false,
+        'prepare' => false,
+        'ssl' => false,
+        'transactions' => false,
     );
 
     /**
      * A mapping of native error codes to DB error codes
      * @var array
      */
-    var $errorcode_map = array(
-    );
+    public $errorcode_map = array();
 
     /**
      * The raw database connection created by PHP
      * @var resource
      */
-    var $connection;
+    public $connection;
 
     /**
      * The DSN information for connecting to a database
      * @var array
      */
-    var $dsn = array();
+    public $dsn = array();
 
 
     /**
      * A means of emulating result resources
      * @var array
      */
-    var $res_row = array();
+    public $res_row = array();
 
     /**
      * The quantity of results so far
@@ -116,7 +116,7 @@ class DB_dbase extends DB_common
      *
      * @var integer
      */
-    var $result = 0;
+    public $result = 0;
 
     /**
      * Maps dbase data type id's to human readable strings
@@ -127,7 +127,7 @@ class DB_dbase extends DB_common
      * @var array
      * @since Property available since Release 1.7.0
      */
-    var $types = array(
+    public $types = array(
         'C' => 'character',
         'D' => 'date',
         'L' => 'boolean',
@@ -144,7 +144,7 @@ class DB_dbase extends DB_common
      *
      * @return void
      */
-    function __construct()
+    public function __construct()
     {
         parent::__construct();
     }
@@ -189,17 +189,17 @@ class DB_dbase extends DB_common
      * );
      *
      * $db = DB::connect($dsn, $options);
-     * if (PEAR::isError($db)) {
+     * if ((new PEAR)->isError($db)) {
      *     die($db->getMessage());
      * }
      * </code>
      *
-     * @param array $dsn         the data source name
-     * @param bool  $persistent  should the connection be persistent?
+     * @param array $dsn the data source name
+     * @param bool $persistent should the connection be persistent?
      *
-     * @return int  DB_OK on success. A DB_Error object on failure.
+     * @return int|object
      */
-    function connect($dsn, $persistent = false)
+    public function connect($dsn, $persistent = false)
     {
         if (!PEAR::loadExtension('dbase')) {
             return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
@@ -220,32 +220,48 @@ class DB_dbase extends DB_common
         if (!file_exists($dsn['database'])) {
             $this->dsn['mode'] = 2;
             if (empty($dsn['fields']) || !is_array($dsn['fields'])) {
-                return $this->raiseError(DB_ERROR_CONNECT_FAILED,
-                                         null, null, null,
-                                         'the dbase file does not exist and '
-                                         . 'it could not be created because '
-                                         . 'the "fields" element of the DSN '
-                                         . 'is not properly set');
+                return $this->raiseError(
+                    DB_ERROR_CONNECT_FAILED,
+                    null,
+                    null,
+                    null,
+                    'the dbase file does not exist and '
+                    . 'it could not be created because '
+                    . 'the "fields" element of the DSN '
+                    . 'is not properly set'
+                );
             }
-            $this->connection = @dbase_create($dsn['database'],
-                                              $dsn['fields']);
+            $this->connection = @dbase_create(
+                $dsn['database'],
+                $dsn['fields']
+            );
             if (!$this->connection) {
-                return $this->raiseError(DB_ERROR_CONNECT_FAILED,
-                                         null, null, null,
-                                         'the dbase file does not exist and '
-                                         . 'the attempt to create it failed: '
-                                         . $php_errormsg);
+                return $this->raiseError(
+                    DB_ERROR_CONNECT_FAILED,
+                    null,
+                    null,
+                    null,
+                    'the dbase file does not exist and '
+                    . 'the attempt to create it failed: '
+                    . $php_errormsg
+                );
             }
         } else {
             if (!isset($this->dsn['mode'])) {
                 $this->dsn['mode'] = 0;
             }
-            $this->connection = @dbase_open($dsn['database'],
-                                            $this->dsn['mode']);
+            $this->connection = @dbase_open(
+                $dsn['database'],
+                $this->dsn['mode']
+            );
             if (!$this->connection) {
-                return $this->raiseError(DB_ERROR_CONNECT_FAILED,
-                                         null, null, null,
-                                         $php_errormsg);
+                return $this->raiseError(
+                    DB_ERROR_CONNECT_FAILED,
+                    null,
+                    null,
+                    null,
+                    $php_errormsg
+                );
             }
         }
         return DB_OK;
@@ -259,7 +275,7 @@ class DB_dbase extends DB_common
      *
      * @return bool  TRUE on success, FALSE on failure
      */
-    function disconnect()
+    public function disconnect()
     {
         $ret = @dbase_close($this->connection);
         $this->connection = null;
@@ -269,7 +285,7 @@ class DB_dbase extends DB_common
     // }}}
     // {{{ &query()
 
-    function &query($query = null)
+    public function &query($query = null)
     {
         // emulate result resources
         $this->res_row[(int)$this->result] = 0;
@@ -290,17 +306,17 @@ class DB_dbase extends DB_common
      * DB_result::fetchInto() instead.  It can't be declared "protected"
      * because DB_result is a separate object.
      *
-     * @param resource $result    the query result resource
-     * @param array    $arr       the referenced array to put the data in
-     * @param int      $fetchmode how the resulting array should be indexed
-     * @param int      $rownum    the row number to fetch (0 = first row)
+     * @param resource $result the query result resource
+     * @param array $arr the referenced array to put the data in
+     * @param int $fetchmode how the resulting array should be indexed
+     * @param int $rownum the row number to fetch (0 = first row)
      *
      * @return mixed  DB_OK on success, NULL when the end of a result set is
      *                 reached or on failure
      *
      * @see DB_result::fetchInto()
      */
-    function fetchInto($result, &$arr, $fetchmode, $rownum = null)
+    public function fetchInto($result, &$arr, $fetchmode, $rownum = null)
     {
         if ($rownum === null) {
             $rownum = $this->res_row[(int)$result]++;
@@ -334,13 +350,13 @@ class DB_dbase extends DB_common
      * This method is a no-op for dbase, as there aren't result resources in
      * the same sense as most other database backends.
      *
-     * @param resource $result  PHP's query result resource
+     * @param resource $result PHP's query result resource
      *
      * @return bool  TRUE on success, FALSE if $result is invalid
      *
      * @see DB_result::free()
      */
-    function freeResult($result)
+    public function freeResult($result)
     {
         return true;
     }
@@ -355,13 +371,12 @@ class DB_dbase extends DB_common
      * DB_result::numCols() instead.  It can't be declared "protected"
      * because DB_result is a separate object.
      *
-     * @param resource $result  PHP's query result resource
-     *
+     * @param $foo
      * @return int  the number of columns.  A DB_Error object on failure.
      *
      * @see DB_result::numCols()
      */
-    function numCols($foo)
+    public function numCols($foo)
     {
         return @dbase_numfields($this->connection);
     }
@@ -376,13 +391,12 @@ class DB_dbase extends DB_common
      * DB_result::numRows() instead.  It can't be declared "protected"
      * because DB_result is a separate object.
      *
-     * @param resource $result  PHP's query result resource
-     *
+     * @param $foo
      * @return int  the number of rows.  A DB_Error object on failure.
      *
      * @see DB_result::numRows()
      */
-    function numRows($foo)
+    public function numRows($foo)
     {
         return @dbase_numrecords($this->connection);
     }
@@ -399,34 +413,39 @@ class DB_dbase extends DB_common
      * @see DB_common::quoteSmart()
      * @since Method available since release 1.7.8.
      */
-    function quoteBoolean($boolean) {
+    public function quoteBoolean($boolean)
+    {
         return $boolean ? 'T' : 'F';
     }
-     
+
     // }}}
     // {{{ tableInfo()
 
     /**
      * Returns information about the current database
      *
-     * @param mixed $result  THIS IS UNUSED IN DBASE.  The current database
+     * @param mixed $result THIS IS UNUSED IN DBASE.  The current database
      *                       is examined regardless of what is provided here.
-     * @param int   $mode    a valid tableInfo mode
+     * @param int $mode a valid tableInfo mode
      *
-     * @return array  an associative array with the information requested.
+     * @return array|object
      *                 A DB_Error object on failure.
      *
      * @see DB_common::tableInfo()
      * @since Method available since Release 1.7.0
      */
-    function tableInfo($result = null, $mode = null)
+    public function tableInfo($result = null, $mode = null)
     {
         if (function_exists('dbase_get_header_info')) {
             $id = @dbase_get_header_info($this->connection);
             if (!$id && $php_errormsg) {
-                return $this->raiseError(DB_ERROR,
-                                         null, null, null,
-                                         $php_errormsg);
+                return $this->raiseError(
+                    DB_ERROR,
+                    null,
+                    null,
+                    null,
+                    $php_errormsg
+                );
             }
         } else {
             /*
@@ -436,13 +455,17 @@ class DB_dbase extends DB_common
              */
             $db = @fopen($this->dsn['database'], 'r');
             if (!$db) {
-                return $this->raiseError(DB_ERROR_CONNECT_FAILED,
-                                         null, null, null,
-                                         $php_errormsg);
+                return $this->raiseError(
+                    DB_ERROR_CONNECT_FAILED,
+                    null,
+                    null,
+                    null,
+                    $php_errormsg
+                );
             }
 
             $id = array();
-            $i  = 0;
+            $i = 0;
 
             $line = fread($db, 32);
             while (!feof($db)) {
@@ -453,8 +476,8 @@ class DB_dbase extends DB_common
                     $pos = strpos(substr($line, 0, 10), chr(0));
                     $pos = ($pos == 0 ? 10 : $pos);
                     $id[$i] = array(
-                        'name'   => substr($line, 0, $pos),
-                        'type'   => $this->types[substr($line, 11, 1)],
+                        'name' => substr($line, 0, $pos),
+                        'type' => $this->types[substr($line, 11, 1)],
                         'length' => ord(substr($line, 16, 1)),
                         'precision' => ord(substr($line, 17, 1)),
                     );
@@ -471,7 +494,7 @@ class DB_dbase extends DB_common
             $case_func = 'strval';
         }
 
-        $res   = array();
+        $res = array();
         $count = count($id);
 
         if ($mode) {
@@ -481,9 +504,9 @@ class DB_dbase extends DB_common
         for ($i = 0; $i < $count; $i++) {
             $res[$i] = array(
                 'table' => $this->dsn['database'],
-                'name'  => $case_func($id[$i]['name']),
-                'type'  => $id[$i]['type'],
-                'len'   => $id[$i]['length'],
+                'name' => $case_func($id[$i]['name']),
+                'type' => $id[$i]['type'],
+                'len' => $id[$i]['length'],
                 'flags' => ''
             );
             if ($mode & DB_TABLEINFO_ORDER) {
@@ -506,5 +529,3 @@ class DB_dbase extends DB_common
  * c-basic-offset: 4
  * End:
  */
-
-?>