Re: why DBD::mysql need database name for connecttion ?

<[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.general
Message-ID <OF6372C194.0477E2E3-ON8625792C.0049AD47-8625792C.004A03C0@discover.com>
Paul DuBois <[email protected]> wrote on 10/14/2011 10:40:21 PM:

> Paul DuBois <[email protected]> 
> 10/14/2011 10:41 PM
> 
> To
> 
> Bill Ward <[email protected]>
> 
> cc
> 
> ZhangJun <[email protected]>, <[email protected]>
> 
> Subject
> 
> Re: why DBD::mysql need database name for connecttion ?
> 
> 
> On Oct 14, 2011, at 7:31 PM, Bill Ward wrote:
> 
> > On Fri, Oct 14, 2011 at 5:26 PM, ZhangJun <[email protected]> wrote:
> > 
> >> 
> >> in the pod:
> >> 
> >> ####################
> >>  Class Methods
> >>      connect
> >>              use DBI;
> >> 
> >>              $dsn = "DBI:mysql:$database";
> >>              $dsn = "DBI:mysql:database=$database;host=$hostname";
> >>              $dsn =
> >> "DBI:mysql:database=$database;host=$hostname;port=$port";
> >> 
> >>              $dbh = DBI->connect($dsn, $user, $password);
> >> 
> >>          A "database" must always be specified.
> >> 
> >> ###################
> >> 
> >> why database is needed ?
> >> the mysqlclient can connect to server without this, and then select
> >> database.
> >> 
> >> 
> > You need to connect to a database before issuing any database 
commands.
> 
> Not necessarily. SHOW DATABASES, for example, doesn't need any 
> database selected.

http://search.cpan.org/~capttofu/DBD-mysql-4.020/lib/DBD/mysql.pm#Server_Administration 


The docs do tell how to run commands without a database but its not as 
obvious as connecting without a database name.

> 
> In the connect call, the database following the second colon 
> actually is optional.
> The second colon, I believe, is not.

So is the official CPAN documentation wrong then? It does explicitly say "
A database must always be specified. "
 
> So "DBI:mysql:" is legal. Or "DBI:mysql::hostname" if you want to 
> specify a hostname.
> 
> 
> > The
> > mysql client just makes that easier to do interactively. In Perl you 
could
> > just create a different object for each database if you need to 
connect to
> > more than one. Why is this a problem?
> > 
> > -- 
> > Check out my LEGO blog at http://www.brickpile.com/
> > View my photos at http://flickr.com/photos/billward/
> > Follow me at http://twitter.com/williamward
> 
> 


Please consider the environment before printing this email.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.