<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>最优良人 &#187; sql</title>
	<atom:link href="http://www.zui88.com/view-tag/sql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.zui88.com/blog</link>
	<description>中山php&#124;最优网络</description>
	<lastBuildDate>Mon, 13 May 2013 04:56:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>phpmyadmin导出的sql如何通过php导入</title>
		<link>http://www.zui88.com/blog/view-374.html</link>
		<comments>http://www.zui88.com/blog/view-374.html#comments</comments>
		<pubDate>Mon, 04 Jun 2012 04:15:01 +0000</pubDate>
		<dc:creator>lin</dc:creator>
				<category><![CDATA[后端程序]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.zui88.com/blog/?p=374</guid>
		<description><![CDATA[以下函数可以直接把从phpmyadmin导出的sql文件直接通过php插入数据库： //$file表示通过读取sql文件返回的字符串，比如$file2=file_get_contents('db.sql'); function import($file2){ $Db = new Db(); $file2=explode("\n",$file2);//将文件内容按行读入到数组 $c1=count($file2); for($j=0;$j&#60;$c1;$j++) { $ck=substr($file2[$j],0,4);//取每行的前4个字符 if( ereg("#",$ck)&#124;&#124;ereg("--",$ck) )//去掉注释 { continue; } $arr[]=$file2[$j];//将去掉注释的文件内容按行读入数组$arr,数组每个元素对应一行 } $read=implode("\n",$arr); //重新组织文件内容到一个字符串,(按照原来分好的一行一行的) $sql=str_replace("\r",'',$read);//去掉"\r(回车符)" $detail=explode(";\n",$sql); //将经上述整理过的文件内容再次按一条完整的sql语句(以;和\n分隔)导入到数组$detail, //此时数组detail的每个元素对应一条完整的sql语句 $count=count($detail); for($i=0;$i&#60;$count;$i++) { $sql=str_replace("\r",'',$detail[$i]);//去掉每行sql中的回车符 $sql=str_replace("\n",'',$sql);//去掉换行符 $sql=trim($sql);//去掉前后空格 //现在的$sql $Db-&#62;query($sql); } }]]></description>
			<content:encoded><![CDATA[<p>以下函数可以直接把从phpmyadmin导出的sql文件直接通过php插入数据库：</p>
<p>//$file表示通过读取sql文件返回的字符串，比如$file2=file_get_contents('db.sql');</p>
<p>function import($file2){</p>
<p>$Db = new Db();<br />
$file2=explode("\n",$file2);//将文件内容按行读入到数组</p>
<p>$c1=count($file2);<br />
for($j=0;$j&lt;$c1;$j++)<br />
{<br />
$ck=substr($file2[$j],0,4);//取每行的前4个字符<br />
if( ereg("#",$ck)||ereg("--",$ck) )//去掉注释<br />
{<br />
continue;<br />
}<br />
$arr[]=$file2[$j];//将去掉注释的文件内容按行读入数组$arr,数组每个元素对应一行<br />
}<br />
$read=implode("\n",$arr); //重新组织文件内容到一个字符串,(按照原来分好的一行一行的)<br />
$sql=str_replace("\r",'',$read);//去掉"\r(回车符)"</p>
<p>$detail=explode(";\n",$sql);<br />
//将经上述整理过的文件内容再次按一条完整的sql语句(以;和\n分隔)导入到数组$detail,<br />
//此时数组detail的每个元素对应一条完整的sql语句<br />
$count=count($detail);<br />
for($i=0;$i&lt;$count;$i++)<br />
{<br />
$sql=str_replace("\r",'',$detail[$i]);//去掉每行sql中的回车符<br />
$sql=str_replace("\n",'',$sql);//去掉换行符<br />
$sql=trim($sql);//去掉前后空格<br />
//现在的$sql<br />
$Db-&gt;query($sql);</p>
<p>}</p>
<p>}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zui88.com/blog/view-374.html/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>
