Home Database Mysql Tutorial 通过PHP取得MySQL procedure结果_MySQL

通过PHP取得MySQL procedure结果_MySQL

Jun 01, 2016 pm 01:59 PM
how storage

总有网友问我,如何通过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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Huawei will launch innovative MED storage products next year: rack capacity exceeds 10 PB and power consumption is less than 2 kW Huawei will launch innovative MED storage products next year: rack capacity exceeds 10 PB and power consumption is less than 2 kW Mar 07, 2024 pm 10:43 PM

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 Vue3+TS+Vite development skills: how to encrypt and store data Sep 10, 2023 pm 04:51 PM

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

How to clear cache on Windows 11: Detailed tutorial with pictures How to clear cache on Windows 11: Detailed tutorial with pictures Apr 24, 2023 pm 09:37 PM

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

Git installation process on Ubuntu Git installation process on Ubuntu Mar 20, 2024 pm 04:51 PM

Git installation process on Ubuntu

How to correctly use sessionStorage to protect sensitive data How to correctly use sessionStorage to protect sensitive data Jan 13, 2024 am 11:54 AM

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 Full analysis of Java collection framework: dissecting data structure and revealing the secret of efficient storage Feb 23, 2024 am 10:49 AM

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? How do PHP and swoole achieve efficient data caching and storage? Jul 23, 2023 pm 04:03 PM

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

Methods and techniques for data caching and storage using PHP arrays Methods and techniques for data caching and storage using PHP arrays Jul 16, 2023 pm 02:33 PM

Methods and techniques for data caching and storage using PHP arrays

See all articles