Guest User

Untitled

a guest
May 25th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 KB | None | 0 0
  1. <?php
  2. class Obj {
  3.  
  4. };
  5.  
  6. class CSVImport {
  7.     public $glistID;
  8.     public $csvData;
  9.     private $preparedData;
  10.  
  11.     function __construct($csv, $listID) {
  12.         $this->glistID = $listID;
  13.         $obj = new Obj();
  14.         $lines = preg_split("/[\r\n]+/", $csv);
  15.         $tags = preg_split("/[\t]/", $lines[0]);
  16.  
  17.         for ($y = 0; $y < count($tags); $y++) {
  18.             $tags[$y] = trim(strtolower(str_replace(" ", "", $tags[$y])));
  19.         }
  20.  
  21.         $objects = array();
  22.  
  23.         for ($line = 1; $line < count($lines); $line++) {
  24.             //echo trim($lines[$line]);  
  25.             $entry = preg_split("/[\t]/", $lines[$line]);
  26.             //print_r($entry);
  27.             $objects[$line - 1] = new Obj();
  28.  
  29.             for ($tag = 0; $tag < count($tags); $tag++) {
  30.                 $objects[$line - 1] -> $tags[$tag] = $entry[$tag];
  31.             }
  32.  
  33.             $this -> preparedData = $objects;
  34.         }
  35.     }
  36.  
  37.     public function Send_To_Database() {
  38.         $data = $this -> preparedData;
  39.         $host = 'guestster.com';
  40.         $db = 'dreaddco_guestlist';
  41.         $DBH = new PDO("mysql:host=$host;dbname=$db", "dreaddco_gladmin", "M1ch9014!!");
  42.  
  43.         for ($x = 0; $x < count($data); $x++) {
  44.             //print_r($data[$x]);
  45.  
  46.            
  47.             //echo $data[$x] -> listID;
  48.  
  49.             $STH = $DBH -> prepare("INSERT INTO guests (listID, firstName, lastName, email, host, phone, affiliation, notes) values (:listID, :firstName, :lastName, :email, :host, :phone, :affiliation, :notes)");
  50.             $STH -> bindParam(':listID', $this->glistID);
  51.             $STH -> bindParam(':firstName', $data[$x] -> firstName);
  52.             $STH -> bindParam(':lastName', $data[$x] -> lastName);
  53.             $STH -> bindParam(':email', $data[$x] -> email);
  54.             $STH -> bindParam(':phone', $data[$x] -> phone);
  55.             //$STH -> bindParam(':addGuests', $data[$x] -> addGuests);
  56.             $STH -> bindParam(':affiliation', $data[$x] -> affiliation);
  57.             $STH -> bindParam(':notes', $data[$x] -> notes);
  58.             $STH -> bindParam(':host', $data[$x]-> host);
  59.             $STH -> execute();
  60.  
  61.             $err = $STH -> errorInfo();
  62.         }
  63.  
  64.     }
  65.  
  66. }
  67. ?>
Add Comment
Please, Sign In to add comment