Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Problem Inserting into Sql Server Database

by peacemaker1820 (Pilgrim)
on Aug 22, 2002 at 21:05 UTC ( [id://192176]=perlquestion: print w/replies, xml ) Need Help??

peacemaker1820 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks
I have a problem. I seem to be doing everything correct, but my info is not getting into the database. IF you notice, I put an error tracking statement print $dbh->errstr right before the executtion takes place. I tried to put this statement after the execute statemtn but it didn't execute. So the error i get is this "DBI::db=HASH(0x2305378)->errstr"
Any Ideas?? Thanks
use DBI; #database parameters my ( $data_source, $database, $user_id, $password ) =qw ( servername d +omain username password ); my $conn_string = "driver={SQL Server}; Server=$data_source; Database= +$database; UID=$user_id; PWD=$password"; #Connect the database handle. my $dbh = DBI->connect("DBI:ODBC:$conn_string") or die "$DBI::errstr\n +"; $insertSQL = <<'EndOfSQL'; INSERT INTO delivery (customerNo,salesOrderNo,sequenceNo,incrementNo,requestDate,quantity,d +eliveryDate,externalNotes,shipVia) VALUES(?,?,?,?,?,?,?,?,?) EndOfSQL my $insertHandle = $dbh->prepare($insertSQL) or die "Problem creat +ing inserting handle: ", $dbh->errstr; ########### show error ########## print "$dbh->errstr"; $insertHandle->execute('customerNo', 'salesOrderNo', 'sequenceNo', 'none', 'dateD', 'quantityD', 'dateD', 'none', 'companyD') or die "Problem Inserting: ", $dbh->errstr; #EndofSQL # Execute the query $SQL->execute() || die "Couldn't execute statement: $DBI::errstr\n"; $rowCount = $SQL->commit(); $dbh->disconnect();

Replies are listed 'Best First'.
Re: Problem Inserting into Sql Server Database
by trs80 (Priest) on Aug 22, 2002 at 22:56 UTC
    Two questions:
    1. Are you sending real values in place of the ones you have in the execute? If not it is most likely a type mismatch between the fields and the data you are supplying.

    2. Where does the $SQL->execute come from? If that is connected with the above insert, I would imagine it would be something like:
    my $rowCount = $insertHandle->commit();
    getting rid of the $SQL->execute all together, unless it is a separate command that isn't included in the sample you provided. Regardless if you have to commit a change you need to do it on the correct database handle at some point I would assume.
Re: Problem Inserting into Sql Server Database
by VSarkiss (Monsignor) on Aug 22, 2002 at 21:36 UTC

    You're making a string instead of invoking the method. Just take the quotes off: print $dbh->errstr;

Re: Problem Inserting into Sql Server Database
by richardX (Pilgrim) on Aug 22, 2002 at 22:23 UTC
    Neil Gunton has an example of using MySQL and Perl together that seems pretty cool and well documented:

    http://www.neilgunton.com/utils/mysearchbot

    Richard

    There are three types of people in this world, those that can count and those that cannot. Anon

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://192176]
Approved by VSarkiss
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-25 14:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found