Jump to content

steeve_84

New Members
  • Posts

    9
  • Joined

  • Last visited

steeve_84's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi! Thanks for all reply, I solved it. $link = new mysqli($host,$user,$pass,$mydb); $link->query ("DELETE FROM " .$table. ""); if (($handle = fopen($file, "r")) !== FALSE) { while (($data = fgetcsv($handle, 10000, ";")) !== FALSE) { if( count($data) !== 36 ) continue; $i=0; foreach($data as $elem){ $data[$i] = str_replace("'","",$elem); $i++; } $sql = "INSERT IGNORE INTO " .$table. " VALUES ('" . implode("','", $data) . "');"; // echo $sql."<br \>"; $link->query ($sql) or die ($link->error); } fclose($handle); }
  2. I know it, but I want to skip rows, where doesn't match column numbers. Now this rows are 1. and 6434, but the at next time can it be the 6328. or other.
  3. OK, changed to: $sql="INSERT IGNORE INTO " .$table. "VALUES (" . implode("';'", $data) . ");"; $link->query ($sql) or die ($link->error); You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0';'';'';'';'';'';'0';'0';'0';'0';'Engedményekhez';'';'';'LOR';'';'0';'';'0';'';' at line 1 If I import the source file at phpmyadmin sql says invalid number of columns.
  4. I'm so sorry. Changed: <?php $row = 1; $host = "localhost"; $user = "root"; $pass = "pass"; $mydb = "database"; $table = "gumiflex"; $link = new mysqli($host,$user,$pass,$mydb); $link->query ("DELETE FROM " .$table. ""); if (($handle = fopen("ftp://user:pass@ftp.hu/data.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 10000, ";")) !== FALSE) { if( count($data) !== 36 ) continue; $num = count($data); $row++; for ($c=0; $c <= $num; $c++) { $link->query ("INSERT IGNORE INTO " .$table. "VALUES (" . implode("';'", $data) . "") or die ($link->error); } } fclose($handle); } ?> You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0';'';'';'';'';'';'0';'0';'0';'0';'Engedményekhez';'';'';'LOR';'';'0';'';'0';'';' at line 1
  5. Hi! I make an another script to import data to my db, but its too wrong... I don't have any idea to solve this. I can't import the fields because at source file are some rows with invalid number of columns, but the scipt don't skip this rows, only write data to the screen but the insert script isn't work. Help Pls! <?php $row = 1; $host = "localhost"; $user = "root"; $pass = "pass"; $mydb = "database"; $table = "gumiflex"; $link = new mysqli($host,$user,$pass,$mydb); $link->query ("DELETE FROM " .$table. ""); if (($handle = fopen("ftp://user:pass@ftp.hu/data.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 10000, ";")) !== FALSE) { if( count($data) !== 36 ) continue; $num = count($data); $row++; for ($c=2; $c <= $num; $c++) { echo $data[$c].";"; $link->query ("INSERT IGNORE INTO " .$table. "VALUES" .$data[$c]); } } fclose($handle); } ?>
  6. Thanks for reply. I make this change, but nothing happens. No errors, simply writes 'OK'.
  7. So.. I changed the code for continue when the column number different from 35, but the data dont writed to table, only the delete query works. <?php $addauto = 1; $delimiter = ';'; $csoport_kod = new mysqli('localhost', 'root', '', '2012'); $csoport_kod->query("DELETE FROM gf1"); $i=1; if (($handle = fopen("ftp://2012.com/gf1.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 10000, $delimiter)) !== FALSE) { if (count($data) !== 35) continue; foreach($data as $i => $content) { $data[$i] = $csoport_kod->real_escape_string($content); } $csoport_kod->query ("INSERT INTO gf1 VALUES('" . implode("','", $data) . "');"); } fclose($handle); } echo 'OK' ?> At the source file the first and 4637. rows have different columns. If I delete this rows the script works, but its not automatic :/
  8. Thx for your reply, The source file I can't change... I make this change, but isnt working... Any other ideas?
  9. Hi, I have a problem with importing .csv file. The content of file have some rows with invalid culomn number. Can I skip rows with this error? My code is: <?php $addauto = 1; $delimiter = ';'; $csoport_kod = new mysqli('localhost', 'root', '', '2012'); $csoport_kod->query("DELETE FROM gf1"); $i=1; if (($handle = fopen("ftp://2012.com/gf1.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 10000, $delimiter)) !== FALSE) { foreach($data as $i => $content) { $data[$i] = $csoport_kod->real_escape_string($content); } $csoport_kod->query ("INSERT ignore INTO gf1 VALUES('" . implode("','", $data) . "');"); } fclose($handle); } echo 'OK' ?> THX!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.