Perl script for Mysql connection -1

 Perl Script to check MySQL connection.


use DBI();
use strict;
use warnings;

print “Content-type:text/htmlnn”;

print “Enter name of DB host (eg.localhost): “;
my $dbhost = <>;

print “Enter name of Database to take backup: “;
my $db = <>;

print “Enter Database user name: “;
my $dbuser = <>;

print “Enter Password: “;
my $dbpass = <>;

print “Enter Path to save backup file: “;
my $bckpath = <>;

print “$dbhost, $db, $dbuser, $dbpass, $bckpath”;

#$connect = Mysql->connect($dbhost, $db, $dbuser, $dbpass);

my $dsn = “DBI:mysql:$db”;
$dsn = “DBI:mysql:database=$db;host=$dbhost”;
my $dbh = DBI->connect($dsn, $dbuser, $dbpass, {RaiseError => 1});

my $sth = $dbh->prepare(“CREATE TABLE dadhichi (         id INT,         data VARCHAR(100)       );”);   –> Here u can use any SQLquery



Neelesh Gurjar has written 122 articles

Leave a Reply