I've written one in Perl for PostgreSQL, using DBI, so it is probably pretty
much the same for MySQL. Below is a sample that shows the top of the file and
then some of the guts that includes connecting to the db, creating the SQL
insert, and then executing it. This is not the full thing, so it will not run
as-is, and may require you to install the proper perl modules on your server in
order to use it. It is also only storing 12 variables for each item ordered, and
is only using one table (so not really using the relational features of a good
SQL database server), but hopefully you'll get the idea. Have fun.
-Loren
#!/usr/bin/perl
use DBI;
use CGI qw(:standard);
# get all name value pairs into $formIn
my $formIn = new CGI;
....
<snip>
....
# connect to the postgres database called lstrans
$dbh = DBI->connect('dbi:Pg:dbname=lstrans', 'admin', undef, { RaiseError => 1,
AutoCommit => 1 });
# print loop to print each unique line item
for ($i = 0; $i < $uniqueitems; $i++){
# create the SQL statement to insert to the lstrans table called transactions
$sql = "INSERT INTO transactions VALUES ( '$orderid', '$siteid', '$timeentered
', '$timecompleted', '@skuarray[$i]', '@quantityarray[$i]', '@amountarray[$i]',
'$currency', '$email', '$paymenttype', '$zipcode', '@namearray[$i]' )";
# now do the SQL statement
$dbh->do($sql) || die("INSERT error: DBI::errstr");
# end the print loop
}
# close/disconnect from the database
$dbh->disconnect;
J Graham wrote:
Hi,
I was wondering if anyone has written a perl script using the Order API to
insert the order data into a MySQL database? It would be great to get all
the order info into a db I can easily access. A perl example (or PHP) would
be a great help!
Thanks,
-Jon
--
Jonathan Graham
www.homeworkout.com