Skip to content

Instantly share code, notes, and snippets.

@allolex
Created March 21, 2012 17:29
Show Gist options
  • Select an option

  • Save allolex/2149867 to your computer and use it in GitHub Desktop.

Select an option

Save allolex/2149867 to your computer and use it in GitHub Desktop.
A simple Zen Cart export Perl script for PHPlist input
#!/usr/bin/env per
use strict;
use warnings;
use DBI;
my $username = 'USERNAME';
my $password = 'PASSWORD';
my $dsn = 'dbi:mysql:DATABASE_NAME;host=HOSTNAME;port=3306';
my $query = qq{
SELECT
c.`customers_email_address`,
c.`customers_firstname`,
c.`customers_lastname`,
c.`customers_email_format`,
a.`entry_city`,
a.`entry_postcode`,
ctry.`countries_iso_code_2`,
ctry.`countries_name`
FROM `eucustomers` c
INNER JOIN `euaddress_book` a ON c.customers_id = a.customers_id
INNER JOIN `eucountries` ctry ON a.entry_country_id = ctry.countries_id
WHERE `customers_newsletter` =1
};
my $dbh = DBI->connect($dsn,$username,$password,
{ RaiseError => 1, AutoCommit => 1 }) or
die "Could not connect to the database.\n" . DBI->errstr . "\n";
my $sth = $dbh->prepare($query);
if ( $sth->execute ) {
my $aref = $sth->fetchall_arrayref;
printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
"Email",
"Firstname",
"Surname",
"Send this user HTML emails",
"City",
"Postcode",
"CountryISO",
"Country";
foreach (@$aref) {
printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
$_->[0],
$_->[1],
$_->[2],
$_->[3] eq 'HTML' ? 1 : 0,
$_->[4],
$_->[5],
$_->[6],
$_->[7];
}
}
else {
warn "Execute failed!\n";
}
$dbh->disconnect();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment