Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Error Messageing

Reply
Thread Tools

Error Messageing

 
 
mike
Guest
Posts: n/a
 
      04-22-2005
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;
}

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      04-22-2005
"mike" <(E-Mail Removed)> wrote:
> 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 =3D "DBI:mysql:database=3Dmydb;host=3D=ADmyhost2";

....

If you don't "use strict;", I won't help you.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      04-22-2005
mike wrote:
> 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?


Yep.

> $dbh -> {RaiseError} = 1;
> $dbh=DBI->connect($dsn, "id", "passwd");


# Add the following here & hopefully you'll see one thing that
# needs to be corrected.
print "The current value of RaiseError is:", $dbh->{'RaiseError'}, "\n";

Also, for simplicity, you can use bind_columns(), and eliminate the
repetitive bind_param() calls.
 
Reply With Quote
 
Glenn Jackman
Guest
Posts: n/a
 
      04-22-2005
At 2005-04-22 11:13AM, J. Gleixner <(E-Mail Removed)> wrote:
> Also, for simplicity, you can use bind_columns(), and eliminate the
> repetitive bind_param() calls.


Or, simplicitiest, pass the values as parameters to execute()
$sth->execute($type, $head, $head_date, $msg, $trans_date, $poster);

--
Glenn Jackman
NCF Sysadmin
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0xffc Thread 0x228 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-30-2006 03:16 PM
Error connecting to SQLExpress 2005 locally (error: 26 - Error Locating Server/Instance Specified) hfk0 ASP .Net 2 03-27-2006 08:43 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 1 03-24-2006 04:20 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-24-2006 02:22 PM
Error 500: ERROR: Cannot forward. Writer or Stream already obtained. Error JavaQueries Java 1 03-01-2005 06:30 PM



Advertisments