195, 'Pain Surprise vide P', '<p>Pain Surprise vide P</p>',14, ' ', ' ', 0
I am testing using a .txt file and while the single quotes were present, the data was not inserted properly to my tables, but after manually removing them to
195, Pain Surprise vide P, <p>Pain Surprise vide P</p>,14, , , 0 the data was inserted correctly.
The code I was using in the text file was as follows:
Code: Select all
<?php
//mysql_connect("127.0.0.1", "root", "") or die (mysql_error());
//mysql_select_db("drupal_db") or die (mysql_error());
//echo "connected to db" ."<br/>";
include("import_article.php");
$path = "sites/path/files/";
$file = "*.txt";
foreach (glob($path.$file) as $filename)
{
$fd = fopen($filename, "r");
while (!feof($fd))
{
$data = fgets($fd);
$delimiter = ",";
$content = explode($delimiter, $data);
//echo 'content:' .$content[0].$content[1].$content[2].$content[3].$content[4].$content[5].$content[6] ."<br/>";
ImportArticle($content[0], $content[1], $content[2], $content[3], $content[4], $content[5], $content[6]);
}
echo "read complete" . "<br/>";
fclose($fd);
}
//echo "close conn";
//mysql_close();
?>
Code: Select all
<?php
// import php file: import_article.php
require("import_article.php");
// mysql_connect("127.0.0.1", "root", "") or die (mysql_error());
// mysql_select_db("drupal_db") or die (mysql_error());
// read first .csv file encountered
$path = "sites/path/files/";
$sfile = "*.csv";
foreach (glob($path.$sfile) as $filename){
echo $filename . "<br/>";
$file = fopen($filename, 'r');
while (($data = fgetcsv($file, ",")) !== False)
{
//echo $data[0]. $data[1]. $data[2]. $data[3]. $data[4]. $data[5]. $data[6]. "<br/>";
ImportArticle($fdta[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6]);
}
echo "read complete";
fclose($file);
// unlink ($filename);
}
// echo "closing connection";
// mysql_close();
?>