怎么写mysql存储过程,并用php调用它?

来源:互联网 发布:淘宝海淘靠谱吗 编辑:程序博客网 时间:2024/05/20 18:43

http://zhidao.baidu.com/link?url=DmmuiPFlAi1XzJdOyqxI980MeuV3iGUM9TdM7zQVkkjt9sMJF92zXKu7YvElrp8-aXHtZ5rp1tMq4yoNrMu_7a


  • 实现原理

  1. 首先,需要知道怎么写mysql存储过程,了解mysq存储过程语言,

  2. 其次,使用mysql工具创建存储过程。

  3. 最后,通过mysql_query()函数执行mysql变量的设置和mysql存储过程及返回值。

  • 具体代码如下:

  1. mysql存储过程代码

create procedure pro_name(user_id int)
begin
.........
end

    2.  PHP代码

$host     "localhost";
$user     "root";
$password "232412";
$db       "user_db";
$dblink   = mysql_connect($host,$user,$password)or die("can't connect to mysql");
mysql_select_db($db,$dblink)or die("can't select user_db");
$user_id  = 1;
$res      = mysql_query("set @a=$user_id",$dblink);
$res      = mysql_query("call pro_name(@a)",$dblink);

0 0
原创粉丝点击