Home > php教程 > php手册 > body text

mysql创建存储过程并在php中调用

WBOY
Release: 2016-06-21 08:49:10
Original
1636 people have browsed it

今天web开发中遇到需要利用php调取mysql的存储过程的,研究了半天终于小有所成,下面将如何使用mysql创建存储过程以及如何使用php调用mysql的存储过程做个记录,以防忘记。

1、在PHPmyadmin中创建一个test1存储过程;

create procedure test1(in a int) //create创建;procedure存储过程;test1是存储过程名还管有没有参数都得加上()
begin //开始
select * from test where id=a;//这里是存储过程的语句
end;//结束
//注:用mysql创建必须把Delimiter改为//
Copy after login

2、在php中调用这个test1存储过程

<?php define('CLIENT_MULTI_RESULTS',131072);//直接取数据取出不来,浪费了一个多小时终于找到这个办法,(通知服务器客户端可以处理由多语句或者存储过程执行生成的多结果集。当打开CLIENT_MULTI_STATEMENTS时,这个标志自动的被打开。可以在本表后查看更多关于该标志位的信息。) 
$link=mysql_connect("localhost", "root", "",1,CLIENT_MULTI_RESULTS) or die("Could not connect: ".mysql_error());
mysql_select_db("yii"); mysql_query("set names utf8");
$resule=mysql_query("call test2(5)");
while($rows=mysql_fetch_array($resule)){
	echo $rows['title']."<br>";
}
Copy after login

文章作者:想象之中 QQ:576272452



Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!