Reputation: 75
Is there a way to check if DB exists using perl ? Its a quick and easy one. but im still getting used to perl and DB
Upvotes: 1
Views: 955
Reputation: 6592
The DBI module is a popular way access and manipulate databases in perl. Here is a short example of usage of DBI which tests a connection:
use DBI;
$user = 'donny';
$pw = 'ppp';
$dsn = 'basetest';
$dbh = DBI->connect($dsn, $user, $pw) or die "Unable to connect: $DBI::errstr\n";
The last line could also be something more like:
$dbh = DBI->connect('dbi:Oracle:',$user.'@'.$password,$dbconnectstring);
Or something similar - just edit the first parameter as makes sense.
As you can see - you'll get unable to connect if the DB can't be found.
Here is the documentation relevant to DBI: http://dbi.perl.org/docs/
Sidenote: Also, note you can access sqlplus - or any command line - within a perl script. Just use backticks. It may be worth it to check that way, if you have the tools available on the machine.
Upvotes: 4