Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: How to find MySQL database exist or not

by edi (Initiate)
on Sep 02, 2011 at 11:12 UTC ( [id://923824]=note: print w/replies, xml ) Need Help??


in reply to Re: How to find MySQL database exist or not
in thread How to find MySQL database exist or not

use DBI; eval { $dbh = DBI->do('dbi:mysql:xxxxxxx','root','') or die "Connection Error: $DBI::errstr\n" } ; if (defined $dbh) { print "Table does not exist.\n"; } else { print "Table exist";}
code will print "Table exist" whether the database exist or not. Please help.

Replies are listed 'Best First'.
Re^3: How to find MySQL database exist or not
by Marshall (Canon) on Sep 03, 2011 at 04:06 UTC
    I think that you are mixing up a couple of things.

    There is a dataset name ($dsn) which is a mySQL database on a particular host name and port number. That has to exist or you are going "nowhere"!

    If the $dsn exists, then you can attempt to connect to it. This is where the user name and passwords are required.

    my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port" || die "DB data set name failed $!\n"; # # second step # # my $dbh = DBI->connect($dsn, $user, $password) || die "DB connect failed $!\n";
    The $dsn and the final connected handle, $dbh are very different things.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://923824]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-26 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found