Forum Moderators: coopster & phranque

Message Too Old, No Replies

Generic error using DBI

         

csdude55

6:31 pm on Dec 22, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm using DBI to read and write MySQL:

[metacpan.org...]

Most of my scripts are running fine, but I have one that's throwing an error that doesn't make sense.

This is the command:

$sth = $dbh->prepare(qq~
REPLACE INTO $whichtable
(username, image, title, city, gender, age, wanting_gender, wanting_age_min, wanting_age_max, zodiac, occupation, attributes, hair, eyes, height, weight, body, education, income, job_importance, alcohol, smoking, wouldbe, adventurous, personality, race, religion, religious_importance, marital, children, description)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
~) or die "prepare statement failed: $dbh->errstr()";

$sth->execute($contents{'username'}, $contents{'pic'}, $contents{'ad_title'}, $contents{'city'}, $contents{'gender'}, $contents{'age'}, $contents{'looking_for'}, $contents{'wanting_age_min'}, $contents{'wanting_age_max'}, $contents{'zodiac'}, $contents{'occupation'}, $contents{'attributes'}, $contents{'hair'}, $contents{'eyes'}, $contents{'height'}, $contents{'weight'}, $contents{'body'}, $contents{'education'}, $contents{'income'}, $contents{'job_importance'}, $contents{'alcohol'}, $contents{'smoking'}, $contents{'wouldbe'}, $contents{'adventurous'}, $contents{'personality'}, $contents{'race'}, $contents{'religion'}, $contents{'religious_importance'}, $contents{'marital'}, $contents{'children'}, $contents{'description'}) or die "execution failed: $dbh->errstr()";


It's dying on the execute() statement, but this is all it says:

execution failed: DBI::db=HASH(0x24b3810)->errstr() at /home/foo/cgi-bin/bar.cgi line 379.


Nothing shows up in the error log.

Any thoughts?

csdude55

12:11 am on Dec 23, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I figured it out... the docs example shows:

my $sth = $dbh->prepare(
'SELECT id, first_name, last_name FROM authors WHERE last_name = ?')
or die "prepare statement failed: $dbh->errstr()";
$sth->execute('Eggers') or die "execution failed: $dbh->errstr()";


But having errstr() in the quotes didn't work; I had to take it out of the quotes to get the error message:

my $sth = $dbh->prepare(
'SELECT id, first_name, last_name FROM authors WHERE last_name = ?')
or die 'prepare statement failed: ' . $dbh->errstr();
$sth->execute('Eggers') or die 'execution failed: ' . $dbh->errstr();