Re: Perl DBI question
От | greg@turnstep.com |
---|---|
Тема | Re: Perl DBI question |
Дата | |
Msg-id | c4f81faedbd5cdb090c86bacf5fce16b@biglumber.com обсуждение исходный текст |
Ответ на | Perl DBI question ("Kovalcik, Mike A [ITS]" <mkoval01@sprintspectrum.com>) |
Ответы |
Re: Perl DBI question
|
Список | pgsql-admin |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 You should not be using the "do" method, but the prepare/execute model instead. Using placeholders can not only be more efficient but allows quoting to happen properly. Here is a rewrite: #--Establish the DB connection #--Assign the DB name my $dbName = 'checkbook'; my $dbuser = "joe"; my $dbpass = "sixpak"; my $dbh = DBI->connect("dbi:Pg:dbname=$dbName", $dbuser, $dbpass, {AutoCommit=>1, RaiseError=>1}) or die "Could not connect to the database: $DBI::errstr\n"; my $SQL = " INSERT INTO transactions (date,description,amount,confirmation,nameid,typeid) VALUES (? ,? ,? ,? ,? ,? )"; my $sth = $dbh->prepare($SQL); my $count = $sth->execute($datePaid,$description,$amount, $confirmation,$nameid,$typeid); print "Insert count: $count\n"; It is hard to tell why your inserts are going wrong without more information, but the RaiseError should at least help catch some obvious errors. - -- Greg Sabino Mullane greg@turnstep.com PGP Key: 0x14964AC8 200306181337 -----BEGIN PGP SIGNATURE----- Comment: http://www.turnstep.com/pgp.html iD8DBQE+8KUHvJuQZxSWSsgRAhWoAJ9/aw9AaCMa5vGvEpvujEEBm4iBXQCggSSw jPaGcdMt9Qq9XeJqttvdX48= =x1nu -----END PGP SIGNATURE-----
В списке pgsql-admin по дате отправления: