Wow, thanks Christa. Excellent idea, (and a very thorough response!) The
only problems is it limits things to MySQL. I was hoping the code could
be database independent (excepting of course the driver)

This is great. Such timely feedback late on a Friday! This is my first
post on this list...Thanks everyone.

On 10/18/02 at 2:40 PM, [EMAIL PROTECTED] (Hastie, Christa)
wrote:

> Well, perhaps you should just connect to the standard 'mysql' db that
> holds the 'db' and 'users' tables, then create the database using
> '$dbh->do' and then add permissions to the 'mysql' db 'db' and
> 'users' tables so the database can be accessed via the new
> permissions set in the 'mysql' db...
> 
> $dbh = DBI->connect("DBI:mysql:mysql;host=$db_host", $db_user,
> $db_password); $dbh->do("CREATE DATABASE '$database_name'");
> 
> $dbh->do("insert into user (host, user, password, select_priv,
> insert_priv, update_priv, delete_priv, create_priv, drop_priv,
> reload_priv, shutdown_priv, process_priv, file_priv, grant_priv,
> references_priv, index_priv, alter_priv) values ('$ip', '$user',
> password('$pass'),
> 'y','y','y','y','y','y','y','y','y','y','y','y','y','y')");
> 
> $dbh->do("insert into db (host, db, user, select_priv, insert_priv,
> update_priv, delete_priv, create_priv, drop_priv, grant_priv,
> references_priv, index_priv, alter_priv) values
> ('$ip','$database_name','$user','Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'N',
> 'N', 'N', 'Y')");
> 
> $dbh->do("flush privileges");
> $dbh->disconnect();
> 
> -----Original Message-----
> From: Andrew Brosnan [mailto:andrew@;broscom.com] 
> Sent: Friday, October 18, 2002 2:23 PM
> To: Jeff Zucker
> Cc: dbi-users
> Subject: Re: Create database
> 
> 
> On 10/18/02 at 2:10 PM, [EMAIL PROTECTED] (Jeff Zucker) wrote:
> 
> > Andrew Brosnan wrote:
> > 
> > > On 10/18/02 at 4:26 PM, [EMAIL PROTECTED] (Hardy Merrill) wrote:
> > > 
> > >>What database are you using?
> > >>
> > > Not sure why it would matter, but MySQL.
> > 
> > 
> > Yes it matters.  This works for me using MySQL:
> > 
> >    my $existing_db = $your_old_db_here;
> >    my $new_db      = $your_new_db_here;
> >    my $dbh = DBI->connect("dbi:mysql:database=$existing_db" ...);
> >    $dbh->do("CREATE DATABASE $new_db");
> >    $dbh->do("USE $newdb");
> >    # commands to create and query tables in $new_db
> > 
> > --
> > Jeff
> > 
> > 
> Yes Jeff, I thought the same thing. But that won't work for me in this
case.
> I need to be able to create a new db without assuming that there is an
> existing one (or at least I might not know what it is).
> 
> What I really need is a way to execute from dbi, what I might normally
do
> via the shell:
> 
> CREATE DATABASE DatabaseName;
> 
> > Yes it matters.
> 
> I assume of course that I would change db drivers in my script as
needed,
> but I'd otherwise like the code to be dbi(data base independant)
> 
> Thanks!!
> 
> Any other thoughts?
> 
> Andrew
> 

Reply via email to