<?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: parsing csv file with php and inserting into mysql database</title>
	<atom:link href="http://www.gsdesign.ro/blog/parsing-csv-file-with-php-and-inserting-into-mysql-database/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gsdesign.ro/blog/parsing-csv-file-with-php-and-inserting-into-mysql-database/</link>
	<description>Just another developer blog</description>
	<lastBuildDate>Wed, 17 Mar 2010 08:39:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Rhiane Caña</title>
		<link>http://www.gsdesign.ro/blog/parsing-csv-file-with-php-and-inserting-into-mysql-database/comment-page-1/#comment-7605</link>
		<dc:creator>Rhiane Caña</dc:creator>
		<pubDate>Thu, 18 Jun 2009 04:08:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.gsdesign.ro/blog/?p=59#comment-7605</guid>
		<description>Hi, Thanks a lot to your blog. It helps me to solve my csv upload. :)&lt;br&gt;&lt;br&gt;Because of your blog, I come up an idea for csv upload. I updated you code.&lt;br&gt;&lt;br&gt;&lt;?php &lt;br&gt;&lt;br&gt; 	$filename = $_FILES[&#039;uploadFile&#039;][&#039;name&#039;];&lt;br&gt;	$file_ext = pathinfo($filename, PATHINFO_EXTENSION);&lt;br&gt;	$file_path = &quot;uploads/&quot;.$filename;&lt;br&gt;&lt;br&gt;	if(strtoupper($file_ext)==&#039;CSV&#039;){&lt;br&gt;		if(move_uploaded_file($_FILES[&quot;uploadFile&quot;][&#039;tmp_name&#039;],$file_path)){&lt;br&gt;			&lt;br&gt;			$file1 = fopen($file_path, &#039;r&#039;);&lt;br&gt;			// initialize header...&lt;br&gt;			$ctr1 = 0;&lt;br&gt;			while(($data1 = fgetcsv($file1 , 1000, &quot;,&quot;)) !== FALSE){&lt;br&gt;				if($ctr1==0){&lt;br&gt;					foreach($data1 as $v1){&lt;br&gt;						$insert_headers[] = &quot;&#039;&quot;. addslashes(trim($v1)) .&quot;&#039;&quot;;				&lt;br&gt;					}&lt;br&gt;					$columns = implode(&#039;,&#039;, $insert_headers);&lt;br&gt;					unset($insert_headers);&lt;br&gt;					$ctr1 = 1;&lt;br&gt;				}&lt;br&gt;			}&lt;br&gt;			fclose($file1);&lt;br&gt;			&lt;br&gt;			&lt;br&gt;			$file = fopen($file_path, &#039;r&#039;);&lt;br&gt;			&lt;br&gt;			// initialize data...&lt;br&gt;			$ctr2 = 0;&lt;br&gt;			while(($data = fgetcsv($file , 1000, &quot;,&quot;)) !== FALSE){&lt;br&gt;				foreach($data as $v){&lt;br&gt;					$insert_values[] = &quot;&#039;&quot;. addslashes(trim($v)) .&quot;&#039;&quot;;			&lt;br&gt;				}&lt;br&gt;&lt;br&gt;				$values = implode(&#039;,&#039;, $insert_values);&lt;br&gt;				unset($insert_values);&lt;br&gt;				&lt;br&gt;				if($ctr2!=0){&lt;br&gt;					$sql_query = &quot;INSERT INTO &lt;br&gt;									tbl_article_info($columns) &lt;br&gt;								  VALUES($values)&quot;;&lt;br&gt;				}&lt;br&gt;				else{&lt;br&gt;					$ctr2 = 1;&lt;br&gt;				}&lt;br&gt;				&lt;br&gt;				mysql_query($sql_query) or die(&quot;Query Error:&quot; . mysql_error());&lt;br&gt;			}&lt;br&gt;			fclose($file);&lt;br&gt;&lt;br&gt;			echo &quot;success&quot;;&lt;br&gt;		}&lt;br&gt;		else{&lt;br&gt;			echo &#039;failed&#039;;&lt;br&gt;		}&lt;br&gt;	}&lt;br&gt;	else{&lt;br&gt;		echo &quot;THE FILE IS NOT IN CSV FORMAT.&quot;;&lt;br&gt;	}&lt;br&gt;?&gt;</description>
		<content:encoded><![CDATA[<p>Hi, Thanks a lot to your blog. It helps me to solve my csv upload. <img src='http://www.gsdesign.ro/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Because of your blog, I come up an idea for csv upload. I updated you code.</p>
<p>&lt;?php </p>
<p> 	$filename = $_FILES[&#39;uploadFile&#39;][&#39;name&#39;];<br />	$file_ext = pathinfo($filename, PATHINFO_EXTENSION);<br />	$file_path = &#8220;uploads/&#8221;.$filename;</p>
<p>	if(strtoupper($file_ext)==&#39;CSV&#39;){<br />		if(move_uploaded_file($_FILES["uploadFile"][&#39;tmp_name&#39;],$file_path)){</p>
<p>			$file1 = fopen($file_path, &#39;r&#39;);<br />			// initialize header&#8230;<br />			$ctr1 = 0;<br />			while(($data1 = fgetcsv($file1 , 1000, &#8220;,&#8221;)) !== FALSE){<br />				if($ctr1==0){<br />					foreach($data1 as $v1){<br />						$insert_headers[] = &#8220;&#39;&#8221;. addslashes(trim($v1)) .&#8221;&#39;&#8221;;				<br />					}<br />					$columns = implode(&#39;,&#39;, $insert_headers);<br />					unset($insert_headers);<br />					$ctr1 = 1;<br />				}<br />			}<br />			fclose($file1);</p>
<p>			$file = fopen($file_path, &#39;r&#39;);</p>
<p>			// initialize data&#8230;<br />			$ctr2 = 0;<br />			while(($data = fgetcsv($file , 1000, &#8220;,&#8221;)) !== FALSE){<br />				foreach($data as $v){<br />					$insert_values[] = &#8220;&#39;&#8221;. addslashes(trim($v)) .&#8221;&#39;&#8221;;			<br />				}</p>
<p>				$values = implode(&#39;,&#39;, $insert_values);<br />				unset($insert_values);</p>
<p>				if($ctr2!=0){<br />					$sql_query = &#8220;INSERT INTO <br />									tbl_article_info($columns) <br />								  VALUES($values)&#8221;;<br />				}<br />				else{<br />					$ctr2 = 1;<br />				}</p>
<p>				mysql_query($sql_query) or die(&#8220;Query Error:&#8221; . mysql_error());<br />			}<br />			fclose($file);</p>
<p>			echo &#8220;success&#8221;;<br />		}<br />		else{<br />			echo &#39;failed&#39;;<br />		}<br />	}<br />	else{<br />		echo &#8220;THE FILE IS NOT IN CSV FORMAT.&#8221;;<br />	}<br />?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yanti</title>
		<link>http://www.gsdesign.ro/blog/parsing-csv-file-with-php-and-inserting-into-mysql-database/comment-page-1/#comment-7523</link>
		<dc:creator>yanti</dc:creator>
		<pubDate>Thu, 14 May 2009 07:31:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.gsdesign.ro/blog/?p=59#comment-7523</guid>
		<description>the code is like this,..

if(isset($_POST[&#039;submit&#039;]))
   {
$columns = &quot;no_ahli, no_pin, nama, no_ic_baru, no_ic_lama&quot;;
$handle = fopen(&quot;filename.csv&quot;, &quot;r&quot;);
while (($data = fgetcsv($handle, 1000, &quot;,&quot;)) !== FALSE) {
  foreach( $data as $v ) {
     $insertValues=&quot;&#039;&quot;.addslashes(trim($v)).&quot;&#039;&quot;;
  }
  $values=implode(&#039;,&#039;,$insertValues);
  $sql = &quot;INSERT INTO `kmmb_member1` ( $columns ) VALUES ( $values )&quot;;
  mysql_query($sql) or die(&#039;SQL ERROR:&#039;.mysql_error());
}
fclose($handle); 
print &quot;Import done&quot;;
   }
   else
   {
 
      print &quot;&quot;;
      print &quot;Type file name to import:&quot;;
      print &quot;&quot;;
      print &quot;&quot;;
   }</description>
		<content:encoded><![CDATA[<p>the code is like this,..</p>
<p>if(isset($_POST['submit']))<br />
   {<br />
$columns = &#8220;no_ahli, no_pin, nama, no_ic_baru, no_ic_lama&#8221;;<br />
$handle = fopen(&#8220;filename.csv&#8221;, &#8220;r&#8221;);<br />
while (($data = fgetcsv($handle, 1000, &#8220;,&#8221;)) !== FALSE) {<br />
  foreach( $data as $v ) {<br />
     $insertValues=&#8221;&#8216;&#8221;.addslashes(trim($v)).&#8221;&#8216;&#8221;;<br />
  }<br />
  $values=implode(&#8216;,&#8217;,$insertValues);<br />
  $sql = &#8220;INSERT INTO `kmmb_member1` ( $columns ) VALUES ( $values )&#8221;;<br />
  mysql_query($sql) or die(&#8216;SQL ERROR:&#8217;.mysql_error());<br />
}<br />
fclose($handle);<br />
print &#8220;Import done&#8221;;<br />
   }<br />
   else<br />
   {</p>
<p>      print &#8220;&#8221;;<br />
      print &#8220;Type file name to import:&#8221;;<br />
      print &#8220;&#8221;;<br />
      print &#8220;&#8221;;<br />
   }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabi Solomon</title>
		<link>http://www.gsdesign.ro/blog/parsing-csv-file-with-php-and-inserting-into-mysql-database/comment-page-1/#comment-7522</link>
		<dc:creator>Gabi Solomon</dc:creator>
		<pubDate>Thu, 14 May 2009 07:18:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.gsdesign.ro/blog/?p=59#comment-7522</guid>
		<description>it means you have a different number of columns in mysql then in your CSV file</description>
		<content:encoded><![CDATA[<p>it means you have a different number of columns in mysql then in your CSV file</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yanti</title>
		<link>http://www.gsdesign.ro/blog/parsing-csv-file-with-php-and-inserting-into-mysql-database/comment-page-1/#comment-7521</link>
		<dc:creator>yanti</dc:creator>
		<pubDate>Thu, 14 May 2009 06:45:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.gsdesign.ro/blog/?p=59#comment-7521</guid>
		<description>hi,...i had tried use ur code but it gives me an error saying that SQL error: Column count doesnt match with values count in 1 row...
wht does it mean?</description>
		<content:encoded><![CDATA[<p>hi,&#8230;i had tried use ur code but it gives me an error saying that SQL error: Column count doesnt match with values count in 1 row&#8230;<br />
wht does it mean?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabi Solomon</title>
		<link>http://www.gsdesign.ro/blog/parsing-csv-file-with-php-and-inserting-into-mysql-database/comment-page-1/#comment-7479</link>
		<dc:creator>Gabi Solomon</dc:creator>
		<pubDate>Wed, 15 Apr 2009 20:15:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.gsdesign.ro/blog/?p=59#comment-7479</guid>
		<description>@Tom
I agree with you that is a much more faster option.
This was just to show how you could do it with php.</description>
		<content:encoded><![CDATA[<p>@Tom<br />
I agree with you that is a much more faster option.<br />
This was just to show how you could do it with php.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Schäfer</title>
		<link>http://www.gsdesign.ro/blog/parsing-csv-file-with-php-and-inserting-into-mysql-database/comment-page-1/#comment-7478</link>
		<dc:creator>Tom Schäfer</dc:creator>
		<pubDate>Wed, 15 Apr 2009 19:44:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.gsdesign.ro/blog/?p=59#comment-7478</guid>
		<description>Your way of importing csv data is too slow.
Ever thought of using LOAD DATA INFILE ? 
The major work is to clean corrupted file data. But these operations have their focus on normalizing the columns in the import files. (Unicode checks, Linebreaks converting, identifying separators and delimiters)

When these works are done, an import of big files is very fast.
1 million lines in less then 60 seconds. The same row by row lasts 10 minutes and more.
Cheers.</description>
		<content:encoded><![CDATA[<p>Your way of importing csv data is too slow.<br />
Ever thought of using LOAD DATA INFILE ?<br />
The major work is to clean corrupted file data. But these operations have their focus on normalizing the columns in the import files. (Unicode checks, Linebreaks converting, identifying separators and delimiters)</p>
<p>When these works are done, an import of big files is very fast.<br />
1 million lines in less then 60 seconds. The same row by row lasts 10 minutes and more.<br />
Cheers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabi Solomon</title>
		<link>http://www.gsdesign.ro/blog/parsing-csv-file-with-php-and-inserting-into-mysql-database/comment-page-1/#comment-7196</link>
		<dc:creator>Gabi Solomon</dc:creator>
		<pubDate>Tue, 25 Nov 2008 15:45:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.gsdesign.ro/blog/?p=59#comment-7196</guid>
		<description>thanks for the error spoting :)
fixed</description>
		<content:encoded><![CDATA[<p>thanks for the error spoting <img src='http://www.gsdesign.ro/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
fixed</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wordpressfun</title>
		<link>http://www.gsdesign.ro/blog/parsing-csv-file-with-php-and-inserting-into-mysql-database/comment-page-1/#comment-7195</link>
		<dc:creator>wordpressfun</dc:creator>
		<pubDate>Tue, 25 Nov 2008 15:24:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.gsdesign.ro/blog/?p=59#comment-7195</guid>
		<description>Cool!
In progress of work of our post a found little error.

$values=inplode(&#039;,&#039;,$insertValues);

Please, change to

$values=implode(&#039;,&#039;,$insertValues);</description>
		<content:encoded><![CDATA[<p>Cool!<br />
In progress of work of our post a found little error.</p>
<p>$values=inplode(&#8216;,&#8217;,$insertValues);</p>
<p>Please, change to</p>
<p>$values=implode(&#8216;,&#8217;,$insertValues);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabi Solomon</title>
		<link>http://www.gsdesign.ro/blog/parsing-csv-file-with-php-and-inserting-into-mysql-database/comment-page-1/#comment-7171</link>
		<dc:creator>Gabi Solomon</dc:creator>
		<pubDate>Thu, 20 Nov 2008 23:39:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.gsdesign.ro/blog/?p=59#comment-7171</guid>
		<description>a where condition to do what ?
sorry i dont follow</description>
		<content:encoded><![CDATA[<p>a where condition to do what ?<br />
sorry i dont follow</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: xdrone</title>
		<link>http://www.gsdesign.ro/blog/parsing-csv-file-with-php-and-inserting-into-mysql-database/comment-page-1/#comment-7168</link>
		<dc:creator>xdrone</dc:creator>
		<pubDate>Thu, 20 Nov 2008 18:51:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.gsdesign.ro/blog/?p=59#comment-7168</guid>
		<description>How do I ad a where clause if my csv contains a column id.</description>
		<content:encoded><![CDATA[<p>How do I ad a where clause if my csv contains a column id.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
