<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: PHP script to import csv data into mysql</title>
	<atom:link href="http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/</link>
	<description>Find useful tips and tricks related to your every day techy needs</description>
	<lastBuildDate>Fri, 23 Jul 2010 01:23:09 -0400</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Darwin</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-21005</link>
		<dc:creator>Darwin</dc:creator>
		<pubDate>Fri, 23 Jul 2010 01:23:09 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-21005</guid>
		<description>Hmm.. i got errors like this “File is not writable, check permissions. Found a total of 2 records in this csv file.” any idea what went wrong?</description>
		<content:encoded><![CDATA[<p>Hmm.. i got errors like this “File is not writable, check permissions. Found a total of 2 records in this csv file.” any idea what went wrong?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darwin</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-21004</link>
		<dc:creator>Darwin</dc:creator>
		<pubDate>Fri, 23 Jul 2010 01:21:53 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-21004</guid>
		<description>Hmm.. i got errors like this &quot;File is not writable, check permissions. Found a total of 2 records in this csv file.&quot; any idea what went wrong?</description>
		<content:encoded><![CDATA[<p>Hmm.. i got errors like this &#8220;File is not writable, check permissions. Found a total of 2 records in this csv file.&#8221; any idea what went wrong?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pollux</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-20716</link>
		<dc:creator>pollux</dc:creator>
		<pubDate>Thu, 24 Jun 2010 15:28:00 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-20716</guid>
		<description>To skip the first line/row which is a header in csv file do this:
.....
if( $lines &gt; 1) {

  if($addauto)
    $query = &quot;insert into $databasetable values(&#039;&#039;,&#039;$linemysql&#039;);&quot;;
  else
   $query = &quot;insert into $databasetable values(&#039;$linemysql&#039;);&quot;;

  $queries .= $query . &quot;\n&quot;;
  @mysql_query($query);
}</description>
		<content:encoded><![CDATA[<p>To skip the first line/row which is a header in csv file do this:<br />
&#8230;..<br />
if( $lines &gt; 1) {</p>
<p>  if($addauto)<br />
    $query = &#8220;insert into $databasetable values(&#8221;,&#8217;$linemysql&#8217;);&#8221;;<br />
  else<br />
   $query = &#8220;insert into $databasetable values(&#8216;$linemysql&#8217;);&#8221;;</p>
<p>  $queries .= $query . &#8220;\n&#8221;;<br />
  @mysql_query($query);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: newbie</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-20622</link>
		<dc:creator>newbie</dc:creator>
		<pubDate>Tue, 15 Jun 2010 02:41:18 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-20622</guid>
		<description>I had this script running good under a different domain.  Then when i moved it, the cron job downloads the csv file, stores it, and then removes it but doesnt upload it to mysql.  When i look at the import.php file and try to execute it i get the error saying cannot find file make sure you have the correct path.  Help.</description>
		<content:encoded><![CDATA[<p>I had this script running good under a different domain.  Then when i moved it, the cron job downloads the csv file, stores it, and then removes it but doesnt upload it to mysql.  When i look at the import.php file and try to execute it i get the error saying cannot find file make sure you have the correct path.  Help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gio</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-20488</link>
		<dc:creator>gio</dc:creator>
		<pubDate>Sat, 05 Jun 2010 19:55:15 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-20488</guid>
		<description>If you want to avoid inserting the first row, just play with the counter, for example:

$lines = 1;                ( The value for the counter is 1)
$queries = &quot;&quot;;
$linearray = array();

foreach(split($lineseparator,$csvcontent) as $line) {

	$lines++;        ( Assigns the first line #2 (header)
	
	if ($lines&gt;=3){   (Start at #3 &quot;anything higher or equal to 3&quot;)</description>
		<content:encoded><![CDATA[<p>If you want to avoid inserting the first row, just play with the counter, for example:</p>
<p>$lines = 1;                ( The value for the counter is 1)<br />
$queries = &#8220;&#8221;;<br />
$linearray = array();</p>
<p>foreach(split($lineseparator,$csvcontent) as $line) {</p>
<p>	$lines++;        ( Assigns the first line #2 (header)</p>
<p>	if ($lines&gt;=3){   (Start at #3 &#8220;anything higher or equal to 3&#8243;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Coulton</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-20485</link>
		<dc:creator>Coulton</dc:creator>
		<pubDate>Sat, 05 Jun 2010 14:55:27 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-20485</guid>
		<description>Wonderful script but I am having reoccurring problems.
After I run the script, it says &quot;Found a total of 1 records in this csv file.&quot;.
I looked back in my table and it shows a blank.
I checked to make sure there was the right number of columns and there were.
Please help!

Thanks,
Coulton</description>
		<content:encoded><![CDATA[<p>Wonderful script but I am having reoccurring problems.<br />
After I run the script, it says &#8220;Found a total of 1 records in this csv file.&#8221;.<br />
I looked back in my table and it shows a blank.<br />
I checked to make sure there was the right number of columns and there were.<br />
Please help!</p>
<p>Thanks,<br />
Coulton</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: saman</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-20430</link>
		<dc:creator>saman</dc:creator>
		<pubDate>Thu, 03 Jun 2010 06:10:10 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-20430</guid>
		<description>If I am restricted to access client&#039;s harddrive how am I going to upload the csv file to the server.for example can we set default value to file upload control</description>
		<content:encoded><![CDATA[<p>If I am restricted to access client&#8217;s harddrive how am I going to upload the csv file to the server.for example can we set default value to file upload control</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alejandro</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-19925</link>
		<dc:creator>alejandro</dc:creator>
		<pubDate>Tue, 11 May 2010 09:03:39 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-19925</guid>
		<description>This was very useful to me... but I needed to make a modification for reading in large files.  I was confused at first, but then realized the script loads the whole file into memory (right?).  So here is a customized version of the code, which reads lines in one at a time.  it reads in files that look like
begin file:
2,3,-1
1,-2,4
end file (with many more values).  i wanted each line to be a table entry and an id with the line number, as well as the first id representing the size of the table (which will not change later).

&lt;?php

/********************************/
/* Code at http://legend.ws/blog/tips-tricks/csv-php-mysql-import/
/* Edit the entries below to reflect the appropriate values
/********************************/
$databasehost = &quot;localhost&quot;;
$databasename = &quot;tomoku&quot;;

$databaseusername =&quot;root&quot;;
$databasepassword = &quot;root&quot;;
$fieldseparator = &quot;\n&quot;;
$lineseparator = &quot;\n&quot;;

// this code reads tatami files into the database

   $con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
@mysql_select_db($databasename) or die(mysql_error());

//this loops over a bunch of files
for($r=2; $r&lt;14; $r++){
  for($c=$r; $c</description>
		<content:encoded><![CDATA[<p>This was very useful to me&#8230; but I needed to make a modification for reading in large files.  I was confused at first, but then realized the script loads the whole file into memory (right?).  So here is a customized version of the code, which reads lines in one at a time.  it reads in files that look like<br />
begin file:<br />
2,3,-1<br />
1,-2,4<br />
end file (with many more values).  i wanted each line to be a table entry and an id with the line number, as well as the first id representing the size of the table (which will not change later).</p>
<p>&lt;?php</p>
<p>/********************************/<br />
/* Code at <a href="http://legend.ws/blog/tips-tricks/csv-php-mysql-import/" rel="nofollow">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/</a><br />
/* Edit the entries below to reflect the appropriate values<br />
/********************************/<br />
$databasehost = &quot;localhost&quot;;<br />
$databasename = &quot;tomoku&quot;;</p>
<p>$databaseusername =&quot;root&quot;;<br />
$databasepassword = &quot;root&quot;;<br />
$fieldseparator = &quot;\n&quot;;<br />
$lineseparator = &quot;\n&quot;;</p>
<p>// this code reads tatami files into the database</p>
<p>   $con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());<br />
@mysql_select_db($databasename) or die(mysql_error());</p>
<p>//this loops over a bunch of files<br />
for($r=2; $r&lt;14; $r++){<br />
  for($c=$r; $c</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ap.Muthu</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-19661</link>
		<dc:creator>Ap.Muthu</dc:creator>
		<pubDate>Wed, 28 Apr 2010 11:02:56 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-19661</guid>
		<description>The following did the trick for me:
LOAD DATA LOW_PRIORITY LOCAL INFILE 
&#039;C:\\Documents and Settings\\Administrator\\Desktop\\SigmaS1.csv&#039; 
INTO TABLE `mydb`.`mytable` 
FIELDS ESCAPED BY &#039;\\&#039; 
TERMINATED BY &#039;,&#039; 
OPTIONALLY ENCLOSED BY &#039;&quot;&#039; 
LINES TERMINATED BY &#039;\r\n&#039; 
(`user`, `pwd`, `sno`, `amt`, `ActiveRec`);</description>
		<content:encoded><![CDATA[<p>The following did the trick for me:<br />
LOAD DATA LOW_PRIORITY LOCAL INFILE<br />
&#8216;C:\\Documents and Settings\\Administrator\\Desktop\\SigmaS1.csv&#8217;<br />
INTO TABLE `mydb`.`mytable`<br />
FIELDS ESCAPED BY &#8216;\\&#8217;<br />
TERMINATED BY &#8216;,&#8217;<br />
OPTIONALLY ENCLOSED BY &#8216;&#8221;&#8216;<br />
LINES TERMINATED BY &#8216;\r\n&#8217;<br />
(`user`, `pwd`, `sno`, `amt`, `ActiveRec`);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peace</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-19520</link>
		<dc:creator>peace</dc:creator>
		<pubDate>Tue, 20 Apr 2010 16:22:44 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-19520</guid>
		<description>The script is reading an extra line from the csv file. e.g if the csv files has 25 records It shows there are 26 records. Can you please tell me where I am going wrong?

I have added to check if it is a first line and continue loop if its first line.

thanks</description>
		<content:encoded><![CDATA[<p>The script is reading an extra line from the csv file. e.g if the csv files has 25 records It shows there are 26 records. Can you please tell me where I am going wrong?</p>
<p>I have added to check if it is a first line and continue loop if its first line.</p>
<p>thanks</p>
]]></content:encoded>
	</item>
</channel>
</rss>
