Created
December 11, 2015 12:38
-
-
Save coquer/99a96e67d525deb490c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class EmailImporter { | |
private $database = "xxx"; | |
private $server = "xx.xx.com"; | |
private $pass = "xxxx"; | |
private $username = "xxx"; | |
public function __contruct(){ | |
echo("Loading ..... \n"); | |
} | |
public function init(){ | |
echo("Initilization ..... \n"); | |
echo("--> Getting data array \n"); | |
$data = $this->get_data_from_server(); | |
echo("Success getting data \n"); | |
echo("--> Writing file \n"); | |
$this->write_file($data); | |
echo("Success writing file \n"); | |
echo("exiting \n"); | |
} | |
private function write_file($data){ | |
echo("Writing to file \n"); | |
$file = 'data.txt'; | |
$current = @file_get_contents($file); | |
foreach ($data as $users) { | |
$name_separation = explode(' ', $users['name']); | |
//[email protected];first name 1;last name 1;m | |
$current .= $users['email'] . ';' . $users['name'] . ';' . " - " . ';' . 'm' . "\n"; | |
} | |
file_put_contents($file, $current); | |
} | |
public function get_data_from_server(){ | |
$data = []; | |
echo("Connectiong to server ..... \n"); | |
$mysqli = new mysqli($this->server, $this->username, $this->pass, $this->database); | |
if ($mysqli->connect_errno) { | |
printf("Connect failed: %s\n", $mysqli->connect_error); | |
exit(); | |
} | |
echo("Success connection :) \n"); | |
echo("\n \n"); | |
echo("Preparing query.... \n"); | |
if ($result = $mysqli->query("SELECT * FROM `jos_emktg_subscriber` WHERE 1 = 1 ORDER BY `subscribe_date` DESC")) { | |
if (!$mysqli->query("SET @a:='this will not work'")) { | |
printf("Error: %s\n", $mysqli->error); | |
} | |
$counter = 0; | |
while($obj = $result->fetch_object()){ | |
$data[$counter] = [ | |
'name' => $obj->name, | |
'email' => $obj->email | |
]; | |
$counter ++; | |
} | |
$result->close(); | |
} | |
$mysqli->close(); | |
return $data; | |
} | |
} | |
$data_object = new EmailImporter(); | |
$data_object->init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment