<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post/1318/</link>
<title><![CDATA[php调用mysql存储过程返回结果集的处理]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Wed, 22 Oct 2008 06:14:04 +0000</pubDate> 
<guid>http://www.jackxiang.com/post/1318/</guid> 
<description>
<![CDATA[ 
	查询当前数据库有哪些存储过程：<br/><br/><div class="code">mysql&gt;show procedure status where Db=&#039;test&#039;</div><br/>创建一个简单的存储过程<br/><br/><br/><div class="code">mysql&gt;create procedure hi() select &#039;hello&#039;;</div><br/><br/>　　5 存储过程创建完毕,看怎么调用它<br/><br/><br/><div class="code">mysql&gt;call hi();</div><br/>　　显示结果　<br/><div class="code">　mysql&gt; call hi();<br/>+-------+<br/>&#124; hello &#124;<br/>+-------+<br/>&#124; hello &#124;<br/>+-------+<br/>1 row in set (0.00 sec)<br/>　　Query OK, 0 rows affected (0.01 sec)</div><br/><br/><br/>删除存储过程：<br/><br/><div class="code">DROP PROCEDURE hi;</div><br/><br/>存储过程实例：<br/><br/><div class="code">DELIMITER &#124;&#124;<br/>CREATE PROCEDURE showdb( v_offset int, v_pagesize int )&nbsp;&nbsp;<br/>BEGIN<br/>&nbsp;&nbsp;SET @stmt = concat(&quot;SELECT * FROM&nbsp;&nbsp;`comment` ORDER BY id DESC LIMIT &quot;,v_offset,&quot;,&quot;,v_pagesize); <br/>&nbsp;&nbsp;PREPARE s1 FROM @stmt;<br/>&nbsp;&nbsp;EXECUTE s1;<br/>&nbsp;&nbsp;DEALLOCATE PREPARE s1;<br/>END&#124;&#124;<br/>DELIMITER ;</div><br/><br/>PHP调用存储过程：<br/>返回单个数据:<br/>1.1:创建MySQL存储过程:<br/><br/><br/><div class="code">DELIMITER $$<br/><br/>DROP PROCEDURE IF EXISTS `test`.`proc_test` $$<br/>CREATE PROCEDURE `test`.`proc_test` (out a int)<br/>BEGIN<br/>&nbsp;&nbsp;&nbsp;&nbsp;select count(*) into a from tblname;<br/>END $$<br/><br/>DELIMITER ;</div><br/><br/>1.2:PHP调用:<br/><br/><br/><div class="code">$db-&gt;query(&quot;CALL test.proc_test(@a)&quot;);<br/>$res = $db-&gt;query(&quot;select @a&quot;);<br/>$row = $res-&gt;fetch_array();<br/>echo $row&#91;&#039;@a&#039;&#93;;</div><br/><br/>返回多个数据:<br/>2.1:创建MySQL存储过程:<br/><br/><br/><div class="code">DELIMITER $$<br/><br/>DROP PROCEDURE IF EXISTS `test`.`proc_test` $$<br/>CREATE PROCEDURE `test`.`proc_test` ()<br/>BEGIN<br/>&nbsp;&nbsp;&nbsp;&nbsp;select * from tbl_name;<br/>END $$<br/><br/>DELIMITER ;</div><br/><br/>2.2:PHP调用:<br/><br/><br/><div class="code">$res=$db-&gt;query(&quot;CALL test.proc_test()&quot;);<br/>while ($arr=$res-&gt;fetch_array())<br/>&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;echo $arr&#91;&quot;Field&quot;&#93; .&quot;&lt;br/&gt;&quot;;<br/>&#125;</div><br/><br/>P.S.:以上代码执行通过环境 PHP 5.X.X + MySQL 5.X.X <br/><br/><br/><br/><div class="code">1 define(&#039;CLIENT_MULTI_RESULTS&#039;, 131072);<br/>2 <br/>3 $link = mysql_connect(&quot;127.0.0.1&quot;, &quot;root&quot;, &quot;&quot;,1,CLIENT_MULTI_RESULTS) or die(&quot;Could not connect: &quot;.mysql_error());</div><br/>下面就可以正常使用了，以下是例子程序：<br/><br/><br/><div class="code">1 &lt;?php<br/> 2&nbsp;&nbsp;&nbsp;&nbsp; define(&#039;CLIENT_MULTI_RESULTS&#039;, 131072);<br/> 3 <br/> 4&nbsp;&nbsp;&nbsp;&nbsp; $link = mysql_connect(&quot;127.0.0.1&quot;, &quot;root&quot;, &quot;&quot;,1,CLIENT_MULTI_RESULTS) or die(&quot;Could not connect: &quot;.mysql_error());<br/> 5&nbsp;&nbsp;&nbsp;&nbsp; mysql_select_db(&quot;vs&quot;) or die(&quot;Could not select database&quot;);<br/> 6 ?&gt;<br/> 7 <br/> 8 &lt;?php<br/> 9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $result = mysql_query(&quot;call get_news_from_class_id(2)&quot;) or die(&quot;Query failed:&quot; .mysql_error());<br/>10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while($row = mysql_fetch_array($result, MYSQL_ASSOC))<br/>11&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#123;<br/>12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $line = &#039;&lt;tr&gt;&lt;td&gt;&lt;a target = _blank href=&#92;&#039;&#039;.$row&#91;&quot;url&quot;&#93;.&#039;&#92;&#039;&gt;&#039;.$row&#91;&quot;title&quot;&#93;.&#039;(&#039;.$row&#91;&quot;page_time&quot;&#93;.&#039;)&#039;.&#039;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&#039;;<br/>14&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo $line;<br/>15&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;&#92;n&quot;);<br/>16 <br/>17&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>18&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mysql_free_result($result);<br/>19 ?&gt;<br/>20 <br/>21 &lt;?php<br/>22&nbsp;&nbsp;&nbsp;&nbsp; mysql_close($link);<br/>23 ?&gt;</div>
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post/1318/#blogcomment51419</link>
<title><![CDATA[[评论] php调用mysql存储过程返回结果集的处理]]></title> 
<author>fff &lt;ceshi@163.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 03 Apr 2009 03:23:51 +0000</pubDate> 
<guid>http://www.jackxiang.com/post/1318/#blogcomment51419</guid> 
<description>
<![CDATA[ 
	查询代码不对吧
]]>
</description>
</item>
</channel>
</rss>