通过PHP取得MySQL procedure结果_MySQL
总有网友问我,如何通过php调用MySQL的存储过程同时取得返回的结果集呢?确实,MySQL的存储过程大大方便了编程也提高了效率。但是,对于那些还在用php 4 的同学们来说可就麻烦了,因为php 4只能调用存储过程,但却无法直接取得返回结果集;不过,用php 5的mysqli函数就可以做到了。首先,重新编译php 5,增加对mysqli的支持,或者直接下载mysqli的扩展模块,这里不再细说。直接举个例子吧:
1、创建存储过程,列出 test 库下的所有表:
mysql>DELIMITER //mysql>CREATE PROCEDURE `yejr`()->BEGIN->SHOW TABLES;->END; //Query OK, 0 rows affected (0.12 sec)mysql>DELIMITER ;mysql>CALL yejr();+------------------+| Tables_in_test |+------------------+| yejr1 || yejr2 |+------------------+
2、用 mysqli 编写测试代码:
$mysqli = new mysqli("localhost", "root", "", "test");if (mysqli_connect_errno()) {printf("Connect failed: %s/n", mysqli_connect_error());exit();}$query = "call yejr();";if ($result = $mysqli->query( $query)) {while($row = $result->fetch_row()){printf ("find table: %s /n", $row[0]);}}$result->close();?>
结果大致如下:
find table: yejr1
find table: yejr2

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Huawei will launch innovative MED storage products next year: rack capacity exceeds 10 PB and power consumption is less than 2 kW

Vue3+TS+Vite development skills: how to encrypt and store data

How to clear cache on Windows 11: Detailed tutorial with pictures

How to correctly use sessionStorage to protect sensitive data

Full analysis of Java collection framework: dissecting data structure and revealing the secret of efficient storage

How do PHP and swoole achieve efficient data caching and storage?

Methods and techniques for data caching and storage using PHP arrays
