sasori Posted October 15, 2010 Share Posted October 15, 2010 hi, i have the class here, and am trying to save the read column of the textfile to db. but unfortunately it's not being save, i don't know what's wrong... I also attached the textfile so you'll have an idea what am i trying to read from class Extractor { public $filehandler; public $data = array(); // set your db access details private $host = HOST; private $username = USERNAME; private $password = PASSWORD; private $dbname = DBNAME; public function __construct($file) { $this->filehandler = $file; } //prints col1 of textfile public function printcol1() { $fp = fopen($this->filehandler,'r'); while(($this->data = fgetcsv($fp,1000,",")) !== FALSE) { # $this->data[0]."<br />"; $this->savetodb($this->data[0]); } fclose($fp); } public function savetodb($data) { try{ $pdo = new PDO("mysql:host=$this->host;dbname=$this->dbname",$this->username,$this->password); $pdo->exec("INSERT INTO test(col,id) VALUES ({$data},null)"); $pdo = null; }catch(PDOException $e){ echo $e->getMessage()."<br />"; } } } $file = 'iso3166.txt'; $shit = new Extractor($file); $shit->printcol1(); [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/215908-saving-read-txtfile-data-to-db-help/ Share on other sites More sharing options...
sasori Posted October 15, 2010 Author Share Posted October 15, 2010 nevermind....was able to solve by creating a non-OOP script instead lol Link to comment https://forums.phpfreaks.com/topic/215908-saving-read-txtfile-data-to-db-help/#findComment-1122393 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.