<?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; mysql</title>
	<atom:link href="http://www.boluor.com/tag/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.boluor.com</link>
	<description></description>
	<lastBuildDate>Fri, 07 Oct 2011 07:28:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>批量修改文章中的标签</title>
		<link>http://www.boluor.com/update-tags-of-posts-in-batch.html</link>
		<comments>http://www.boluor.com/update-tags-of-posts-in-batch.html#comments</comments>
		<pubDate>Sat, 22 Aug 2009 20:19:56 +0000</pubDate>
		<dc:creator>boluor</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[正则表达式]]></category>

		<guid isPermaLink="false">http://www.boluor.com/?p=299</guid>
		<description><![CDATA[<p>　　实在受不了syntax highlighter的速度，所以暂时去找了个wp-syntax高亮插件来代替。问题来了，我之前使用时标签都是类似：［c］［/c］，［php］［/php］的，当时偷懒不想写完整的标签。但是wp-syntax只支持类似&#60;pre lang=”language” line=”1&#8243;&#62;&#60;/pre&#62;之类的标签。只好想法去修改了，但是手工修改的工作量太大，于是继续想懒办法。<br />
　　解决的方法肯定是正则表达式了。所以用php写了个，数据库就按照wp的结构来。下面是代码：<br />
<span id="more-299"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:Courier new,verdana;"><span style="color: #000000; font-weight: bold;">&#60;?php</span>
	<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#34;localhost&#038;qu</span></pre></div></div><p>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>　　实在受不了syntax highlighter的速度，所以暂时去找了个wp-syntax高亮插件来代替。问题来了，我之前使用时标签都是类似：［c］［/c］，［php］［/php］的，当时偷懒不想写完整的标签。但是wp-syntax只支持类似&lt;pre lang=”language” line=”1&#8243;&gt;&lt;/pre&gt;之类的标签。只好想法去修改了，但是手工修改的工作量太大，于是继续想懒办法。<br />
　　解决的方法肯定是正则表达式了。所以用php写了个，数据库就按照wp的结构来。下面是代码：<br />
<span id="more-299"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:Courier new,verdana;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span> <span style="color: #339933;">,</span>  <span style="color: #0000ff;">&quot;mysqlname&quot;</span> <span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;passwd&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;can't connect to server&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//这句很关键，如果不设定，读取的全部是乱码，update后数据库中保存的也就成乱码了。</span>
	<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SET NAMES 'UTF8'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dbname&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//修改所有文章.</span>
	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select ID ,post_content from wp_posts&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span>MYSQL_ASSOC<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$rst</span> <span style="color: #339933;">=</span> rp<span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;post_content&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;ID&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$sqlupdate</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;update wp_posts set post_content = '<span style="color: #006699; font-weight: bold;">$rst</span>' where ID = <span style="color: #006699; font-weight: bold;">$id</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sqlupdate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #666666; font-style: italic;">//sleep(10);这句话如果有的话，执行时间过长。超过了30s的最大执行时间。没找到怎么取消这个时间限制。</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;ok&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//下面是只修改其中一篇文章时的代码.</span>
<span style="color: #666666; font-style: italic;">/*
	$result = mysql_query(&quot;select ID,post_content from wp_posts where ID=197&quot;);
	$row = mysql_fetch_row($result);
	$id = $row[0];	//ID
	$rst = rp($row[1]);//post_content
	$sqlupdate = &quot;update wp_posts set post_content = '$rst' where ID = $id&quot;;
	mysql_query($sqlupdate);
&nbsp;
	echo &quot;ok&quot;; 
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> rp<span style="color: #009900;">&#40;</span><span style="color: #000088;">$rst</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
    <span style="color: #000088;">$pattern</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
        <span style="color: #0000ff;">&quot;/\[c\](.*?)\[\/c\]/is&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;/\[cpp\](.*?)\[\/cpp\]/is&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;/\[php\](.*?)\[\/php\]/is&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;/\[css\](.*?)\[\/css\]/is&quot;</span><span style="color: #339933;">,</span>  
        <span style="color: #0000ff;">&quot;/\[html\](.*?)\[\/html\]/is&quot;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #000088;">$replace</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
        <span style="color: #0000ff;">&quot;&lt;pre lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>c<span style="color: #000099; font-weight: bold;">\&quot;</span> line=<span style="color: #000099; font-weight: bold;">\&quot;</span>1<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>{1}&lt;/pre&gt;&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;&lt;pre lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>cpp<span style="color: #000099; font-weight: bold;">\&quot;</span> line=<span style="color: #000099; font-weight: bold;">\&quot;</span>1<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>{1}&lt;/pre&gt;&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;&lt;pre lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>php<span style="color: #000099; font-weight: bold;">\&quot;</span> line=<span style="color: #000099; font-weight: bold;">\&quot;</span>1<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>{1}&lt;/pre&gt;&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #0000ff;">&quot;&lt;pre lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>css<span style="color: #000099; font-weight: bold;">\&quot;</span> line=<span style="color: #000099; font-weight: bold;">\&quot;</span>1<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>{1}&lt;/pre&gt;&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">&quot;&lt;pre lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>html<span style="color: #000099; font-weight: bold;">\&quot;</span> line=<span style="color: #000099; font-weight: bold;">\&quot;</span>1<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>{1}&lt;/pre&gt;&quot;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span>  <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pattern</span><span style="color: #339933;">,</span><span style="color: #000088;">$replace</span><span style="color: #339933;">,</span><span style="color: #000088;">$rst</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>　　你看到的我现在的文章，就是用这个方法修改的。不过，遇到点小问题，有几篇竟然没有转换过去，而当我用修改单篇文章的方式修改时又可以，难道是因为我执行时间太短，还是mysql请求太频繁？<br />
　　早上4点20了，要睡了额。</p>
<p>　　<strong>随笔</strong>：很喜欢<a href="http://mindhacks.cn/">刘未鹏大师</a>的一幅画。<br />
<div id="attachment_300" class="wp-caption alignnone" style="width: 310px"><a href="http://www.boluor.com/wp-content/uploads/2009/08/paradoxoflearning-thumb.jpg"><img src="http://www.boluor.com/wp-content/uploads/2009/08/paradoxoflearning-thumb-300x182.jpg" alt="寻找什么和找到了什么" title="paradoxoflearning-thumb" width="300" height="182" class="size-medium wp-image-300" /></a><p class="wp-caption-text">寻找什么和找到了什么</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boluor.com/update-tags-of-posts-in-batch.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>php+mysql+ajax实现留言本</title>
		<link>http://www.boluor.com/php-mysql-ajax-guestbook.html</link>
		<comments>http://www.boluor.com/php-mysql-ajax-guestbook.html#comments</comments>
		<pubDate>Fri, 08 May 2009 00:34:47 +0000</pubDate>
		<dc:creator>boluor</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.boluor.com/blog/?p=34</guid>
		<description><![CDATA[<p>Php+mysql+ajax 实现留言本</p>
<p>闲着无聊，写了个简易的留言本，写下总结吧。</p>
<p>留言本的逻辑很简单，在浏览时将所有的留言显示出来，当用户点击提交新的留言时，将其保存到数据库中。如果不用ajax，那每次更新页面都需要刷新页面，而且需要从服务器将所有的数据down下来，一个增大了服务器的压力，二个给用户很不好的使用体验。所以用ajax来实现异步提交，而且新增的页面上提交的内容，也不需要再从服务器上再down下来，直接更新局部页面即可。</p>
<p>wordpress这个编辑器真是垃圾啊,每次修改code的时候,整个就乱了.代码的缩进就全没了。经过几次折腾后,还是决定提供下载吧&#8230;</p>
<p><a href="http://www.boluor.com/wp-content/uploads/2009/05/phpmysqlajaxe79599e8a880e69cac.rar">php+mysql+a</a>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Php+mysql+ajax 实现留言本</p>
<p>闲着无聊，写了个简易的留言本，写下总结吧。</p>
<p>留言本的逻辑很简单，在浏览时将所有的留言显示出来，当用户点击提交新的留言时，将其保存到数据库中。如果不用ajax，那每次更新页面都需要刷新页面，而且需要从服务器将所有的数据down下来，一个增大了服务器的压力，二个给用户很不好的使用体验。所以用ajax来实现异步提交，而且新增的页面上提交的内容，也不需要再从服务器上再down下来，直接更新局部页面即可。</p>
<p>wordpress这个编辑器真是垃圾啊,每次修改code的时候,整个就乱了.代码的缩进就全没了。经过几次折腾后,还是决定提供下载吧&#8230;</p>
<p><a href="http://www.boluor.com/wp-content/uploads/2009/05/phpmysqlajaxe79599e8a880e69cac.rar">php+mysql+ajax留言本</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boluor.com/php-mysql-ajax-guestbook.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

