1

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

rsharma
  • 75
  • 1
  • 9
  • 1
    http://stackoverflow.com/questions/838978/how-to-check-if-mysql-database-exists – PleaseStand Jan 18 '13 at 20:22
  • 1
    The alternative question [SO 838978](http://stackoverflow.com/q/838978) does not cover Perl at all; this question is specifically about Perl. This question is not a duplicate of that one. – Jonathan Leffler Jan 18 '13 at 21:01

1 Answers1

4

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.

PinkElephantsOnParade
  • 6,452
  • 12
  • 53
  • 91