Listing 2. Database Creation (not complete)
$dbname = 'phonedb';
$dbmain = 'template1';
$dbuser = '';
$dbpass = '';
use DBI;
DBI->trace(2);
##### create database
$dbh = DBI->connect("dbi:Pg:dbname=$dbmain",
$dbuser, $dbpass, {PrintError => 0}) or die $DBI::errstr;
$dbh->do("DROP DATABASE $dbname")
and print "database $dbname has been dropped\n"
or print "database $dbname has not been dropped\n";
$dbh->do("CREATE DATABASE $dbname")
and print "database $dbname has been created\n"
or print "database $dbname has not been created\n";
Copyright © 1994 - 2018 Linux Journal. All rights reserved.