mysql.php - create database issue
| From: | george at mail dot zoomedia dot com | Date: | Tue, 20 Aug 2002 23:44:12 +0000 |
| Subject: | mysql.php - create database issue | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-2162@lists.php.net to get a copy of this message | ||
Hi,
If I create a DSN and try to use PEAR to create a new MySQL database using
code like this:
<?
INI_SET('include_path', ".:/usr/local/lib/php");
require_once('DB.php');
$db = DB::connect("mysql://user:password@localhost");
$sql="create database mydatabase";
$result = $db->query($sql);
if (DB::isError ($result)) die ("Error... :" . $result->getMessage () .
"\n");
?>
I get the error: 'No Database Selected'
This seems to be the case with the following version of DB/mysql.php:
mysql.php,v 1.89.2.1 2002/04/09 19:04:14
which I think is the version that ships with PHP 4.2.2
However, if I use a version of DB/mysql.php from an earlier distro such
as:
mysql.php,v 1.69.2.3 2001/11/13 01:26:42
it works just fine.
Obviously, the problem is that the newer version is complaining that I
haven't specified a database in my DSN. However, the older version seems
more forgiving in this respect, and the newer functionality is arguably
buggy because the PEAR code is basically an abstraction for the following
native MySQL code:
<?
mysql_connect("localhost","user","password");
$sql="create database mydatabase";
mysql_query($sql);
?>
Notice, no mysql_select_db() call was needed for the above to work, nor
should such a call be required when the action is not database dependent
(like CREATE DATABASE)
Any thoughts on whether mysql.php should be modified to work the way it
used to?
Regards,
George Mandella
george at zoomedia dot com