Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Obj {
- };
- class CSVImport {
- public $glistID;
- public $csvData;
- private $preparedData;
- function __construct($csv, $listID) {
- $this->glistID = $listID;
- $obj = new Obj();
- $lines = preg_split("/[\r\n]+/", $csv);
- $tags = preg_split("/[\t]/", $lines[0]);
- for ($y = 0; $y < count($tags); $y++) {
- $tags[$y] = trim(strtolower(str_replace(" ", "", $tags[$y])));
- }
- $objects = array();
- for ($line = 1; $line < count($lines); $line++) {
- //echo trim($lines[$line]);
- $entry = preg_split("/[\t]/", $lines[$line]);
- //print_r($entry);
- $objects[$line - 1] = new Obj();
- for ($tag = 0; $tag < count($tags); $tag++) {
- $objects[$line - 1] -> $tags[$tag] = $entry[$tag];
- }
- $this -> preparedData = $objects;
- }
- }
- public function Send_To_Database() {
- $data = $this -> preparedData;
- $host = 'guestster.com';
- $db = 'dreaddco_guestlist';
- $DBH = new PDO("mysql:host=$host;dbname=$db", "dreaddco_gladmin", "M1ch9014!!");
- for ($x = 0; $x < count($data); $x++) {
- //print_r($data[$x]);
- //echo $data[$x] -> listID;
- $STH = $DBH -> prepare("INSERT INTO guests (listID, firstName, lastName, email, host, phone, affiliation, notes) values (:listID, :firstName, :lastName, :email, :host, :phone, :affiliation, :notes)");
- $STH -> bindParam(':listID', $this->glistID);
- $STH -> bindParam(':firstName', $data[$x] -> firstName);
- $STH -> bindParam(':lastName', $data[$x] -> lastName);
- $STH -> bindParam(':email', $data[$x] -> email);
- $STH -> bindParam(':phone', $data[$x] -> phone);
- //$STH -> bindParam(':addGuests', $data[$x] -> addGuests);
- $STH -> bindParam(':affiliation', $data[$x] -> affiliation);
- $STH -> bindParam(':notes', $data[$x] -> notes);
- $STH -> bindParam(':host', $data[$x]-> host);
- $STH -> execute();
- $err = $STH -> errorInfo();
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment