How do I create a database from code in PERL?
I can do it from the MySQL prompt but not within a perl script.
Keith
I can do it from the MySQL prompt but not within a perl script.
Keith
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
CREATE DATABASE DATABASE_NAME
perl -e 'use DBI;'
#!/usr/local/bin/perl
use DBI;
my $dbh = DBI->connect("database","user","password");
if ($DBI::errstr ne "" ){
print "$DBI::errstr";
exit;
}
my $sth = $dbh->prepare ("CREATE DATABASE DATABASE_NAME")
$sth->execute();
$dbh = DBI->connect("DBI:mysql:database=$db;host=$host",
$user, $password, {RaiseError => 1});
$dsn = "DBI:mysql:$database"; #on local host
$dsn = "DBI:mysql:database=$database;host=$hostname"; #remote host
$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; #remote host with non-default port
$dbh = DBI->connect($dsn, $user, $password); #your connect statement
$dbh = DBI->connect("DBI:mysql:database=$db;host=$host",
$user, $password, {RaiseError => 1});
my $dbh = DBI->connect("DBI:mysql:;host=$host",
$user, $password, {RaiseError => 1});
{RaiseError => 1}
The RaiseError attribute can be used to force errors to raise exceptions rather than simply return error codes in the normal way. It is "off" by default. When set "on", any method which results in an error will cause the DBI to effectively do a die("$class $method failed: $DBI::errstr"), where $class is the driver class and $method is the name of the method that failed.