ssb             Fri Feb 16 09:57:06 2001 EDT

  Modified files:              
    /php4/pear/DB       mysql.php 
  Log:
  * load mysql extension if needed
  
  
Index: php4/pear/DB/mysql.php
diff -u php4/pear/DB/mysql.php:1.46 php4/pear/DB/mysql.php:1.47
--- php4/pear/DB/mysql.php:1.46 Fri Feb 16 09:14:40 2001
+++ php4/pear/DB/mysql.php      Fri Feb 16 09:57:06 2001
@@ -51,33 +51,33 @@
     function DB_mysql()
     {
         $this->DB_common();
-       $this->phptype  = "mysql";
-       $this->dbsyntax = "mysql";
-       $this->features = array(
-           "prepare"       => false,
-           "pconnect"      => true,
-           "transactions"  => false
-       );
-
-       $this->errorcode_map = array(
-           1004 => DB_ERROR_CANNOT_CREATE,
-           1005 => DB_ERROR_CANNOT_CREATE,
-           1006 => DB_ERROR_CANNOT_CREATE,
-           1007 => DB_ERROR_ALREADY_EXISTS,
-           1008 => DB_ERROR_CANNOT_DROP,
-           1046 => DB_ERROR_NODBSELECTED,
+        $this->phptype = "mysql";
+        $this->dbsyntax = "mysql";
+        $this->features = array(
+            "prepare" => false,
+            "pconnect" => true,
+            "transactions" => false
+        );
+        $this->errorcode_map = array(
+            1004 => DB_ERROR_CANNOT_CREATE,
+            1005 => DB_ERROR_CANNOT_CREATE,
+            1006 => DB_ERROR_CANNOT_CREATE,
+            1007 => DB_ERROR_ALREADY_EXISTS,
+            1008 => DB_ERROR_CANNOT_DROP,
+            1046 => DB_ERROR_NODBSELECTED,
             1050 => DB_ERROR_ALREADY_EXISTS,
-           1051 => DB_ERROR_NOSUCHTABLE,
-           1054 => DB_ERROR_NOSUCHFIELD,
-           1062 => DB_ERROR_ALREADY_EXISTS,
-           1064 => DB_ERROR_SYNTAX,
-           1100 => DB_ERROR_NOT_LOCKED,
-           1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
-           1146 => DB_ERROR_NOSUCHTABLE,
-       );
+            1051 => DB_ERROR_NOSUCHTABLE,
+            1054 => DB_ERROR_NOSUCHFIELD,
+            1062 => DB_ERROR_ALREADY_EXISTS,
+            1064 => DB_ERROR_SYNTAX,
+            1100 => DB_ERROR_NOT_LOCKED,
+            1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
+            1146 => DB_ERROR_NOSUCHTABLE,
+        );
     }
 
     // }}}
+
     // {{{ connect()
 
     /**
@@ -92,44 +92,45 @@
     
     function connect($dsn, $persistent = false)
     {
-       if (is_array($dsn)) {
-           $dsninfo = &$dsn;
-       } else {
-           $dsninfo = DB::parseDSN($dsn);
-       }
-
-       if (!$dsninfo || !$dsninfo["phptype"]) {
-           return $this->raiseError(); // XXX ERRORMSG
-       }
+        if (is_array($dsn)) {
+            $dsninfo = &$dsn;
+        } else {
+            $dsninfo = DB::parseDSN($dsn);
+        }
+        
+        if (!$dsninfo || !$dsninfo["phptype"]) {
+            return $this->raiseError(); // XXX ERRORMSG
+        }
        
-       $dbhost = $dsninfo["hostspec"] ? $dsninfo["hostspec"] : "localhost";
-       $user = $dsninfo["username"];
-       $pw = $dsninfo["password"];
-
-       $connect_function = $persistent ? "mysql_pconnect" : "mysql_connect";
-
-       if ($dbhost && $user && $pw) {
-           $conn = $connect_function($dbhost, $user, $pw);
-       } elseif ($dbhost && $user) {
-           $conn = $connect_function($dbhost, $user);
-       } elseif ($dbhost) {
-           $conn = $connect_function($dbhost);
-       } else {
-           $conn = false;
-       }
-
-       if ($conn == false) {
-           return $this->raiseError(); // XXX ERRORMSG
-       }
-
-       if ($dsninfo["database"]) {
-           if (!mysql_select_db($dsninfo["database"], $conn)) {
-               return $this->raiseError(); // XXX ERRORMSG
-           }
-       }
-
-       $this->connection = $conn;
-       return DB_OK;
+        $dbhost = $dsninfo["hostspec"] ? $dsninfo["hostspec"] : "localhost";
+        $user = $dsninfo["username"];
+        $pw = $dsninfo["password"];
+        
+        DB::assertExtension("mysql");
+        $connect_function = $persistent ? "mysql_pconnect" : "mysql_connect";
+        
+        if ($dbhost && $user && $pw) {
+            $conn = $connect_function($dbhost, $user, $pw);
+        } elseif ($dbhost && $user) {
+            $conn = $connect_function($dbhost, $user);
+        } elseif ($dbhost) {
+            $conn = $connect_function($dbhost);
+        } else {
+            $conn = false;
+        }
+        
+        if ($conn == false) {
+            return $this->raiseError(); // XXX ERRORMSG
+        }
+        
+        if ($dsninfo["database"]) {
+            if (!mysql_select_db($dsninfo["database"], $conn)) {
+                return $this->raiseError(); // XXX ERRORMSG
+            }
+        }
+        
+        $this->connection = $conn;
+        return DB_OK;
     }
 
     // }}}
@@ -144,7 +145,7 @@
      */
     function disconnect()
     {
-       return mysql_close($this->connection);
+        return mysql_close($this->connection);
     }
 
     // }}}
@@ -166,12 +167,12 @@
     {
         $this->last_query = $query;
         $query = $this->modifyQuery($query);
-       $result = mysql_query($query, $this->connection);
-       if (!$result) {
-           return $this->mysqlRaiseError();
-       }
-       // Determine which queries that should return data, and which
-       // should return an error code only.
+        $result = mysql_query($query, $this->connection);
+        if (!$result) {
+            return $this->mysqlRaiseError();
+        }
+        // Determine which queries that should return data, and which
+        // should return an error code only.
         return DB::isManip($query) ? DB_OK : $result;
     }
 
@@ -191,27 +192,27 @@
      */
     function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT)
     {
-       if ($fetchmode == DB_FETCHMODE_DEFAULT) {
-           $fetchmode = $this->fetchmode;
-       }
-
-       if ($fetchmode & DB_FETCHMODE_ASSOC) {
-           $row = mysql_fetch_array($result, MYSQL_ASSOC);
-       } else {
-           $row = mysql_fetch_row($result);
-       }
+        if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+            $fetchmode = $this->fetchmode;
+        }
+
+        if ($fetchmode & DB_FETCHMODE_ASSOC) {
+            $row = mysql_fetch_array($result, MYSQL_ASSOC);
+        } else {
+            $row = mysql_fetch_row($result);
+        }
        
-       if (!$row) {
-           $errno = mysql_errno($this->connection);
+        if (!$row) {
+            $errno = mysql_errno($this->connection);
 
-           if (!$errno) {
-               return null;
-           }
+            if (!$errno) {
+                return null;
+            }
            
-           return $this->mysqlRaiseError($errno);
-       }
+            return $this->mysqlRaiseError($errno);
+        }
        
-       return $row;
+        return $row;
     }
 
     // }}}
@@ -230,27 +231,27 @@
      */
     function fetchInto($result, &$arr, $fetchmode = DB_FETCHMODE_DEFAULT)
     {
-       if ($fetchmode == DB_FETCHMODE_DEFAULT) {
-           $fetchmode = $this->fetchmode;
-       }
-
-       if ($fetchmode & DB_FETCHMODE_ASSOC) {
-           $arr = mysql_fetch_array($result, MYSQL_ASSOC);
-       } else {
-           $arr = mysql_fetch_row($result);
-       }
-
-       if (!$arr) {
-           $errno = mysql_errno($this->connection);
-
-           if (!$errno) {
-               return NULL;
-           }
+        if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+            $fetchmode = $this->fetchmode;
+        }
+
+        if ($fetchmode & DB_FETCHMODE_ASSOC) {
+            $arr = mysql_fetch_array($result, MYSQL_ASSOC);
+        } else {
+            $arr = mysql_fetch_row($result);
+        }
+
+        if (!$arr) {
+            $errno = mysql_errno($this->connection);
+
+            if (!$errno) {
+                return NULL;
+            }
 
-           return $this->mysqlRaiseError($errno);
-       }
+            return $this->mysqlRaiseError($errno);
+        }
 
-       return DB_OK;
+        return DB_OK;
     }
 
     // }}}
@@ -267,18 +268,18 @@
      */
     function freeResult($result)
     {
-       if (is_resource($result)) {
-           return mysql_free_result($result);
-       }
-
-       if (!isset($this->prepare_tokens[$result])) {
-           return false;
-       }
+        if (is_resource($result)) {
+            return mysql_free_result($result);
+        }
+
+        if (!isset($this->prepare_tokens[$result])) {
+            return false;
+        }
 
-       unset($this->prepare_tokens[$result]);
-       unset($this->prepare_types[$result]);
+        unset($this->prepare_tokens[$result]);
+        unset($this->prepare_types[$result]);
 
-       return true; 
+        return true; 
     }
 
     // }}}
@@ -295,13 +296,13 @@
      */
     function numCols($result)
     {
-       $cols = mysql_num_fields($result);
+        $cols = mysql_num_fields($result);
 
-       if (!$cols) {
-           return $this->mysqlRaiseError();
-       }
+        if (!$cols) {
+            return $this->mysqlRaiseError();
+        }
 
-       return $cols;
+        return $cols;
     }
 
     // }}}
@@ -335,6 +336,7 @@
      *
      * @return number of rows affected by the last query
      */
+
     function affectedRows()
     {
         if (DB::isManip($this->last_query)) {
@@ -359,7 +361,7 @@
 
     function errorNative()
     {
-       return mysql_errno($this->connection);
+        return mysql_errno($this->connection);
     }
 
     // }}}
@@ -398,7 +400,7 @@
         if (DB::isError($result)) {
             return $result;
         }
-       return mysql_insert_id($this->connection);
+        return mysql_insert_id($this->connection);
     }
                
     // }}}
@@ -453,7 +455,6 @@
     // TODO/wishlist:
     // simpleFetch
     // simpleGet
-    // affectedRows
     // longReadlen
     // binmode
 }

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to