How To: Getting your orders into MySQL in realtime
Posted: Fri Jul 26, 2002 5:08 pm
Thought I'd share how I insert our orders into our MySql database as they
are processed by ShopSite. This technique uses the Order API feature of
ShopSite v6 as well as PHP and of course MySql.
Below is a perl cgi script I wrote that can be submitted as and ShopSite
Order API cgi script. It's basically the same as the sample custom-dump.pl
script, except I write the order data to a file. It's the first step in
storing your orders to a MySQL database as they are processed by Shopsite in
real-time.
At the end of this script I execute a PHP script that then opens the file to
which I just wrote the order data. The PHP script then parses the data file
and creates an insert statement into my MySQL database.
There's probably a variety of ways to do this, but this seemed the most
flexible and easiest to implement.
-Jon
Homeworkout.com
====== Start order.cgi
#!/usr/bin/perl
open (OUT, ">[PATH_TO_MY_ROOTDIR]/orders/data.txt") || die "cant open
outputfile";
my $buffer;
my $method;
if ($ENV{'REQUEST_METHOD'} =~ /get/i) {
$buffer = $ENV{'QUERY_STRING'};
$method = "Get";
}
else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
$method = "Post";
}
my $pair;
my @nvpairs = split(/&/, $buffer);
foreach $pair (@nvpairs)
{
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# Use whatever output format you like in the line below
print OUT "$name ::==:: $value\n";
}
close(OUT);
# The line below may have wrapped - should be one line
my $output = `[PATH_TO_PHP_EXECUTABLE]/php
[PATH_TO_MY_ROOTDIR]/orders/orderprocess.php`;
====== End order.cgi
are processed by ShopSite. This technique uses the Order API feature of
ShopSite v6 as well as PHP and of course MySql.
Below is a perl cgi script I wrote that can be submitted as and ShopSite
Order API cgi script. It's basically the same as the sample custom-dump.pl
script, except I write the order data to a file. It's the first step in
storing your orders to a MySQL database as they are processed by Shopsite in
real-time.
At the end of this script I execute a PHP script that then opens the file to
which I just wrote the order data. The PHP script then parses the data file
and creates an insert statement into my MySQL database.
There's probably a variety of ways to do this, but this seemed the most
flexible and easiest to implement.
-Jon
Homeworkout.com
====== Start order.cgi
#!/usr/bin/perl
open (OUT, ">[PATH_TO_MY_ROOTDIR]/orders/data.txt") || die "cant open
outputfile";
my $buffer;
my $method;
if ($ENV{'REQUEST_METHOD'} =~ /get/i) {
$buffer = $ENV{'QUERY_STRING'};
$method = "Get";
}
else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
$method = "Post";
}
my $pair;
my @nvpairs = split(/&/, $buffer);
foreach $pair (@nvpairs)
{
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# Use whatever output format you like in the line below
print OUT "$name ::==:: $value\n";
}
close(OUT);
# The line below may have wrapped - should be one line
my $output = `[PATH_TO_PHP_EXECUTABLE]/php
[PATH_TO_MY_ROOTDIR]/orders/orderprocess.php`;
====== End order.cgi