Guest User

Untitled

a guest
Sep 17th, 2018
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #!/usr/bin/env per
  2. use strict;
  3. use warnings;
  4. use DBI;
  5.  
  6. my $username = 'USERNAME';
  7. my $password = 'PASSWORD';
  8. my $dsn = 'dbi:mysql:DATABASE_NAME;host=HOSTNAME;port=3306';
  9.  
  10. my $query = qq{
  11. SELECT
  12. c.`customers_email_address`,
  13. c.`customers_firstname`,
  14. c.`customers_lastname`,
  15. c.`customers_email_format`,
  16. a.`entry_city`,
  17. a.`entry_postcode`,
  18. ctry.`countries_iso_code_2`,
  19. ctry.`countries_name`
  20. FROM `eucustomers` c
  21. INNER JOIN `euaddress_book` a ON c.customers_id = a.customers_id
  22. INNER JOIN `eucountries` ctry ON a.entry_country_id = ctry.countries_id
  23. WHERE `customers_newsletter` =1
  24. };
  25.  
  26. my $dbh = DBI->connect($dsn,$username,$password,
  27. { RaiseError => 1, AutoCommit => 1 }) or
  28. die "Could not connect to the database.\n" . DBI->errstr . "\n";
  29.  
  30. my $sth = $dbh->prepare($query);
  31.  
  32. if ( $sth->execute ) {
  33.  
  34. my $aref = $sth->fetchall_arrayref;
  35.  
  36. printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
  37. "Email",
  38. "Firstname",
  39. "Surname",
  40. "Send this user HTML emails",
  41. "City",
  42. "Postcode",
  43. "CountryISO",
  44. "Country";
  45.  
  46. foreach (@$aref) {
  47.  
  48. printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
  49. $_->[0],
  50. $_->[1],
  51. $_->[2],
  52. $_->[3] eq 'HTML' ? 1 : 0,
  53. $_->[4],
  54. $_->[5],
  55. $_->[6],
  56. $_->[7];
  57.  
  58. }
  59.  
  60. }
  61. else {
  62.  
  63. warn "Execute failed!\n";
  64.  
  65. }
  66.  
  67. $dbh->disconnect();
Add Comment
Please, Sign In to add comment