Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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();
Add Comment
Please, Sign In to add comment