M
mike
I was not getting error messages returned using this script. The insert
failed and I didn't get an error message. I had to look in my
error.log.
Anyone see anything wrongs with this?
use DBI;
$dsn = "DBI:mysql:database=mydb;host=myhost2";
$dbh -> {RaiseError} = 1;
$dbh=DBI->connect($dsn, "id", "passwd");
if ( !defined $dbh )
{
die "Cannot connect to mySQl $DBI::errstr\n";
}
else
{
$sql = "insert into my_posts ( type, head, head_date, msg,
trans_date, poster ) values ( ?, ?, ?, ?, ?, ? )";
$sth = $dbh->prepare( $sql );
if ( !defined $sth )
{
print "Cannot prepare statement: $DBI::errstr\n";
}
else
{
$sth->bind_param('1', $type);
$sth->bind_param('2', $head);
$sth->bind_param('3', $head_date);
$sth->bind_param('4',$msg);
$sth->bind_param('5', $trans_date);
$sth->bind_param('6', $poster);
eval { $sth->execute; };
if ( $@ )
{
# I should get an error message here
print "Error in the database: $@";
}
else
{
# execute worked was success
print "<center><b>Insert - Complete</b></center>\n";
}
}
#release the statement
$sth->finish;
#disconnect the database
$dbh->disconnect;
}
failed and I didn't get an error message. I had to look in my
error.log.
Anyone see anything wrongs with this?
use DBI;
$dsn = "DBI:mysql:database=mydb;host=myhost2";
$dbh -> {RaiseError} = 1;
$dbh=DBI->connect($dsn, "id", "passwd");
if ( !defined $dbh )
{
die "Cannot connect to mySQl $DBI::errstr\n";
}
else
{
$sql = "insert into my_posts ( type, head, head_date, msg,
trans_date, poster ) values ( ?, ?, ?, ?, ?, ? )";
$sth = $dbh->prepare( $sql );
if ( !defined $sth )
{
print "Cannot prepare statement: $DBI::errstr\n";
}
else
{
$sth->bind_param('1', $type);
$sth->bind_param('2', $head);
$sth->bind_param('3', $head_date);
$sth->bind_param('4',$msg);
$sth->bind_param('5', $trans_date);
$sth->bind_param('6', $poster);
eval { $sth->execute; };
if ( $@ )
{
# I should get an error message here
print "Error in the database: $@";
}
else
{
# execute worked was success
print "<center><b>Insert - Complete</b></center>\n";
}
}
#release the statement
$sth->finish;
#disconnect the database
$dbh->disconnect;
}