Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

DBI answer! (was Re: ODBC question)

by BBQ (Deacon)
on May 10, 2000 at 07:51 UTC ( #10884=note: print w/ replies, xml ) Need Help??


in reply to ODBC question

Well, the 1st way around it that I can think of would be to drop Win32::ODBC (unless you REALLY need it) and switch do DBD::ODBC! Not only will you be joining the "standard" in perl database programing, but you'll be able to port your code with minor modifications (not to say none) to other database systems. Here's a sample of what you how you would do it:

# 1st prepare the SQL with placeholders $sth = $dbh->prepare(qq{ INSERT INTO Comment ( Field1, Field2 ) VALUES ( ?,? ) }) or die("Failed to prepare ".$DBI::errstr); # now execute what you've prepared with the variables $rv = $sth->execute($val1,$val2) or die("Failed to execute ".$DBI::errstr);
(btrott wrote a complete select example back in March that also addresses placeholders)

Get the general drift? It gets better... Now you're using ODBC, and I'd guess that you're running Access or MS-SQL, right? If you switch to DBI, you'll be able to connect directly to Oracle, Informix, MySQL and others without the need for ODBC standing as a middle man. Seriously, look into DBI/DBDs, you won't regret it!

#!/home/bbq/bin/perl
# Trust no1!


Comment on DBI answer! (was Re: ODBC question)
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://10884]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2014-07-11 07:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (220 votes), past polls