Hello
I am unable to connect to mysql and have tried everything and gone through the forum. Please can you tell me what is wrong here? I have written a perl script and have a subroutine to try and test creating a table, inserting data and then reading from it. However, nothing seems to be happening. Please have a look at this subroutine below
I have tried changing the host variable to mysql-starka.x10hosting.com instead but still doesn't work. I have set up the mysql user and password through the cPanel too.
Please can you help!!!
Thanks
Raj
#!/usr/bin/perl
use DBI;
use DBD::mysql;
print "Content-type: text/html\n\n";
&dbtest();
sub dbtest {
# Config vars
$platform = "mysql";
$database = "rbabbra_execs";
$host = "localhost";
$user = "rbabbra_admin";
$pwd = "my_password";
# Data Source Name (DSN)
$dsn = "dbi:$platform:$database:$host";
# Perl DBI Connect
$dbexecs = DBI->connect($dsn, $user, $pwd) or die "Unable to connect: $DBI::errstr\n";
my $tblcreate=qq[
CREATE TABLE IF NOT EXISTS perlTest (
pkey int(11) NOT NULL auto_increment,
a int,
b int,
c int,
timeEnter timestamp(14),
PRIMARY KEY (pkey)
)];
my $insert= qq[
insert into perlTest (a,b,c)
values (1,2,3),(4,5,6),(7,8,9)];
my $select=qq[
select a,b,c from perlTest];
my $s = $dbexecs->prepare($tblcreate);
$s->execute();
$s = $dbexecs->prepare($insert);
$s->execute();
$s = $dbh->prepare($select);
$s->execute();
while(my @val = $s->fetchrow_array()) {
print " $val[0] $val[1] $val[2]\n";
++$count;
}
$s->finish();
$dbexecs->disconnect();
}
I am unable to connect to mysql and have tried everything and gone through the forum. Please can you tell me what is wrong here? I have written a perl script and have a subroutine to try and test creating a table, inserting data and then reading from it. However, nothing seems to be happening. Please have a look at this subroutine below
I have tried changing the host variable to mysql-starka.x10hosting.com instead but still doesn't work. I have set up the mysql user and password through the cPanel too.
Please can you help!!!
Thanks
Raj
#!/usr/bin/perl
use DBI;
use DBD::mysql;
print "Content-type: text/html\n\n";
&dbtest();
sub dbtest {
# Config vars
$platform = "mysql";
$database = "rbabbra_execs";
$host = "localhost";
$user = "rbabbra_admin";
$pwd = "my_password";
# Data Source Name (DSN)
$dsn = "dbi:$platform:$database:$host";
# Perl DBI Connect
$dbexecs = DBI->connect($dsn, $user, $pwd) or die "Unable to connect: $DBI::errstr\n";
my $tblcreate=qq[
CREATE TABLE IF NOT EXISTS perlTest (
pkey int(11) NOT NULL auto_increment,
a int,
b int,
c int,
timeEnter timestamp(14),
PRIMARY KEY (pkey)
)];
my $insert= qq[
insert into perlTest (a,b,c)
values (1,2,3),(4,5,6),(7,8,9)];
my $select=qq[
select a,b,c from perlTest];
my $s = $dbexecs->prepare($tblcreate);
$s->execute();
$s = $dbexecs->prepare($insert);
$s->execute();
$s = $dbh->prepare($select);
$s->execute();
while(my @val = $s->fetchrow_array()) {
print " $val[0] $val[1] $val[2]\n";
++$count;
}
$s->finish();
$dbexecs->disconnect();
}