cvs: php4 /pear DB.php /pear/DB mysql.php
| From: | Jan Lehnardt | Date: | Tue, 12 Feb 2002 18:29:28 +0000 |
| Subject: | cvs: php4 /pear DB.php /pear/DB mysql.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-2411@lists.php.net to get a copy of this message | ||
jan Tue Feb 12 13:29:28 2002 EDT
Modified files:
/php4/pear DB.php
/php4/pear/DB mysql.php
Log:
- added support for different error messages for the following cases:
-
- if a user with unsufficient permissions trys to select a database
- PEAR::DB previously threw a "no database selected" error instead
- of a more proper "insufficient permissions". This is fixed now.
-
- if a user selects a nonexistant database PEAR::DB threw a
- "no database selected" error instead of "no such database".
- This is fixed as well.
-
- I added two new constants to DB.php and a simple case construct to
- DB/mysql.php which can be easily extended to achive the above. I
- hope this is ok.
- Thanks to Till Gerken for mentioning this.
Index: php4/pear/DB.php
diff -u php4/pear/DB.php:1.85 php4/pear/DB.php:1.86
--- php4/pear/DB.php:1.85 Fri Feb 1 11:36:32 2002
+++ php4/pear/DB.php Tue Feb 12 13:29:27 2002
@@ -17,7 +17,7 @@
// | Tomas V.V.Cox <cox@idecnet.com> |
// +----------------------------------------------------------------------+
//
-// $Id: DB.php,v 1.85 2002/02/01 16:36:32 cox Exp $
+// $Id: DB.php,v 1.86 2002/02/12 18:29:27 jan Exp $
//
// Database independent query interface.
//
@@ -58,6 +58,8 @@
define("DB_ERROR_INVALID_DSN", -23);
define("DB_ERROR_CONNECT_FAILED", -24);
define("DB_ERROR_EXTENSION_NOT_FOUND",-25);
+define("DB_ERROR_NOSUCHDB", -25);
+define("DB_ERROR_ACCESS_VIOLATION", -26);
/*
* Warnings are not detected as errors by DB::isError(), and are not
@@ -385,7 +387,9 @@
DB_WARNING => 'unknown warning',
DB_WARNING_READ_ONLY => 'read only',
DB_ERROR_NEED_MORE_DATA => 'insufficient data supplied',
- DB_ERROR_EXTENSION_NOT_FOUND=> 'extension not found'
+ DB_ERROR_EXTENSION_NOT_FOUND=> 'extension not found',
+ DB_ERROR_NOSUCHDB => 'no such database',
+ DB_ERROR_ACCESS_VIOLATION => 'insufficient permissions'
);
}
Index: php4/pear/DB/mysql.php
diff -u php4/pear/DB/mysql.php:1.86 php4/pear/DB/mysql.php:1.87
--- php4/pear/DB/mysql.php:1.86 Fri Feb 1 19:27:47 2002
+++ php4/pear/DB/mysql.php Tue Feb 12 13:29:27 2002
@@ -17,7 +17,7 @@
// | |
// +----------------------------------------------------------------------+
//
-// $Id: mysql.php,v 1.86 2002/02/02 00:27:47 ssb Exp $
+// $Id: mysql.php,v 1.87 2002/02/12 18:29:27 jan Exp $
//
// Database independent query interface definition for PHP's MySQL
// extension.
@@ -142,8 +142,18 @@
if ($dsninfo['database']) {
if (!@mysql_select_db($dsninfo['database'], $conn)) {
- return $this->raiseError(DB_ERROR_NODBSELECTED, null, null,
- null, mysql_error($conn));
+ switch(mysql_errno($conn)) {
+
+ case 1049:
+ return $this->raiseError(DB_ERROR_NOSUCHDB, null, null,
+ null, mysql_error($conn));
+ break;
+ case 1044:
+ return $this->raiseError(DB_ERROR_ACCESS_VIOLATION, null, null,
+ null, mysql_error($conn));
+ break;
+
+ }
}
// fix to allow calls to different databases in the same script
$this->_db = $dsninfo['database'];