Error Messageing

Discussion in 'Perl Misc' started by mike, Apr 22, 2005.

  1. mike

    mike Guest

    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;
    }
    mike, Apr 22, 2005
    #1
    1. Advertising

  2. mike

    Guest

    "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?
    >
    > 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
    , Apr 22, 2005
    #2
    1. Advertising

  3. mike

    J. Gleixner Guest

    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.
    J. Gleixner, Apr 22, 2005
    #3
  4. At 2005-04-22 11:13AM, J. Gleixner <> 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
    Glenn Jackman, Apr 22, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hfk0
    Replies:
    2
    Views:
    21,638
  2. JavaQueries
    Replies:
    1
    Views:
    3,625
    John C. Bollinger
    Mar 1, 2005
  3. Balaji
    Replies:
    3
    Views:
    10,074
  4. Bishop
    Replies:
    1
    Views:
    760
    Bishop
    Feb 24, 2007
  5. juvi
    Replies:
    3
    Views:
    1,038
    Alexey Smirnov
    Jan 22, 2009
Loading...

Share This Page