http://www.perlmonks.org?node_id=11159892


in reply to Re^2: Perl and Mysql Queries
in thread Perl and Mysql Queries

It's always a good idea (and good defensive programming) to check the results of things as you go. So, I'd write

my $dbh = DBI->connect('dbi:mysql:jobs_db', "Poster', 'Poster Password'); defined $dbh or die "Unable to connect to DB: " . $dbh->errstr; my $sth =$dbh->prepare("INSERT INTO jobs (JobID,EmployerID, EmployerName,Title,City,StateProvince,Description,Function, Sector,Country,Posted) Values(?,?,?,?,?,?,?,?,?,?,?)"); defined $sth or die "Unable to prepare insert: " . $dbh->errstr; $sth->execute($JobID,$EmployerID,$EmployerName,$Title,$City, $StateProvince,$Description,$Function,$Sector,$Country,$Posted) or die "Failed to execute insert: " . $dbh->errstr;
The die statements will leave something informative in your log file, and will give you information about what's failing. And I'm also going to encourage you to add
use strict; use warnings;
at the top of all of your scripts. Generally, your scripts should compile cleanly, and should not put any warnings in the error log. If there are warnings, fix them.

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.