总有网友问我,如何通过php调用mysql的存储过程同时取得返回的结果集呢?确实,mysql的存储过程大大方便了编程也提高了效率。但是,对于那些还在用php 4 的同学们来说可就麻烦了,因为php 4只能调用存储过程,但却无法直接取得返回结果集;不过,用php 5的mysqli函数就可以做到了。首先,重新编译php 5,增加对mysqli的支持,或者直接下载mysqli的扩展模块,这里不再细说。直接举个例子吧:
1、创建存储过程,列出 test 库下的所有表:
| @@######@@ |
| @@######@@ |
find table: yejr1
立即学习“PHP免费学习笔记(深入)”;
find table: yejr2
【相关文章】
<p>mysql>DELIMITER //</p><p>mysql>CREATE PROCEDURE `yejr`()</p><p>->BEGIN</p><p>->SHOW TABLES;</p><p>->END; //</p><p>Query OK, 0 rows affected (0.12 sec)</p><p>mysql>DELIMITER ;</p><p>mysql>CALL yejr();</p><p>+------------------+</p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/970">
<img src="https://img.php.cn/upload/ai_manual/000/000/000/175680015863684.png" alt="火龙果写作">
</a>
<div class="aritcle_card_info">
<a href="/ai/970">火龙果写作</a>
<p>用火龙果,轻松写作,通过校对、改写、扩展等功能实现高质量内容生产。</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="火龙果写作">
<span>106</span>
</div>
</div>
<a href="/ai/970" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="火龙果写作">
</a>
</div>
<p>| Tables_in_test |</p><p>+------------------+</p><p>| yejr1 |</p><p>| yejr2 |</p><p>+------------------+</p><p>$mysqli = new mysqli("localhost", "root", "", "test");</p><p>if (mysqli_connect_errno()) {</p><p>printf("Connect failed: %sn", mysqli_connect_error());</p><p>exit();</p><p>}</p><p>$query = "call yejr();";</p><p>if ($result = $mysqli->query( $query)) {</p><p>while($row = $result->fetch_row())</p><p>{</p><p>printf ("find table: %s n", $row[0]);</p><p>}</p><p>}</p><p>$result->close();</p><p>?><br></p>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号