当前位置:首页 » 存储配置 » pdomysql存储过程

pdomysql存储过程

发布时间: 2023-01-20 10:06:04

Ⅰ mysql 存储过程怎么调用

php调用mysql存储过程和函数的方法
存储过程和函数是MySql5.0刚刚引入的。关于这方面的操作在PHP里面没有直接的支持。但是由于Mysql PHP API的设计,使得我们可以在以前的PHP版本中的mysql php api中支持存储过程和函数的调用。

在php中调用存储过程和函数。

1。调用存储过程的方法。

a。如果存储过程有 IN/INOUT参数,声明一个变量,输入参数给存储过程,该变量是一对,

一个php变量(也可以不必,只是没有php变量时,没有办法进行动态输入),一个Mysql

变量。

b。如果存储过程有OUT变量,声明一个Mysql变量。

mysql变量的声明比较特殊,必须让mysql服务器知道此变量的存在,其实也就是执行一条mysql语句。

入set @mysqlvar=$phpvar ;

c。使用mysql_query()/mysql_db_query()执行mysql 变量声明语句。

mysql_query("set @mysqlvar=$pbpvar");

这样,在mysql服务器里面就有一个变量,@mysqlar。如果是IN参数,那么其值可以由phpar传入。

d。 如果是存储过程。

1。执行 call procere()语句。

也就是mysql_query("call proceer([var1]...)");

2. 如果有返回值,执行select @ar,返回执行结果。

mysql_query("select @var)"

接下来的操作就和php执行一般的mysql语句一样了。可以通过mydql_fetch_row()等函数获得结果。

如果时函数。 直接执行 select function() 就可以了。
$host="localhost";
$user="root";
$password="11212";
$db="samp_db";
$dblink=mysql_connect($host,$user,$password)
or die("can't connect to mysql");
mysql_select_db($db,$dblink)
or die("can't select samp_db");
$res=mysql_query("set @a=$password",$dblink);
$res=mysql_query("call aa(@a)",$dblink);
$res=mysql_query("select @a",$dblink);
$row=mysql_fetch_row($res);
echo $row[0];

Ⅱ mysql数据库存储过程怎么写

创建存储过程
mysql>
delimiter
$
--
delimiter
$是设置
$为命令终止符号,代替默认的分号,因为分号有其他用处.
mysql>
create
procere
sp_test(IN
pi_id
int,
OUT
po_name
varchar(10))
->
begin
->
select
*
from
test.tb_test;
->
select
tb_test.name
into
po_name
from
test.tb_test
where
tb_test.id
=
pi_id;
->
end
->
$
Query
OK,
0
rows
affected
(0.00
sec)
mysql>
delimiter
;
--
恢复分号作为分隔终止符号
5.调用存储过程
mysql>
set
@po_name='';
Query
OK,
0
rows
affected
(0.00
sec)
mysql>
call
sp_test(1,@po_name);

Ⅲ mysql 存储过程

1. exec 存储过程名
2. exec 存储过程名 参数1,参数2,参数3......
或者exec 存储过程名 参数1='',参数2='',参数3=''......

Ⅳ mysql利用存储过程实现批量处理数据的简单操作

-- 判断存储test是否存在,如果存在则删除

DROP PROCEDURE IF EXISTS test;

-- 创建存储过程

CREATE PROCEDURE test()

BEGIN

-- 声明循环变量int型 i

DECLARE i INT DEFAULT 1;

-- 设置i=0

set i=0;

-- 循环100次

while i<100 do

-- if判断i为偶数

if i%2 = 0 THEN

-- 要实现的操作  CONCAT(str1,str2,...) concat函数用于拼接子串和数字类型

INSERT into user(name,addr) VALUES(CONCAT('test',i,'ss'),'addr');

end if;

-- i自增

set i=i+1;

END WHILE;

END;

-- 调用存储过程

CALL test()

Ⅳ mysql 存储过程

你应该在做统计吧,估计你不会的就是mysql存储过程的语法 我之前也写过 很是郁闷 我给你一段代码 是我用mysql写过的一个存储过程 你看看 主要是了解里面的语法 看懂了 你所说的需求并不难
有看不懂的地方一起讨论 :
begin

declare tikk datetime ;
declare done int default 0;
declare userid int default 0;
declare moleid int default 0;
declare couid int default 0;
declare mname varchar(255) ;
declare opsid int default 0;

declare c1 cursor for Select I_userID,I_operationID from space_operation_record where status<>0 group by I_userID,I_operationID order by createtime desc;
declare continue handler for sqlstate '02000' set done =1;
set tikk = now();
open c1;
repeat
fetch c1 into userid, opsid;
if not done then
select I_moleID from space_operation where status<>0 and ID=opsid into moleid;
if moleid <> '' then
select Nvc_identification from space_operation where status<>0 and ID=opsid into @identiftion;
if moleid > 0 then
Select Nvc_ename from space_mole where status<>0 and ID=moleid into mname;
else
set mname = 'space';
end if;

create temporary table if not exists sp_tab1(id bigint(20),Nvc_content MEDIUMTEXT,I_obyuID bigint(20),I_tID bigint(20),createtime datetime);
INSERT INTO sp_tab1 Select ID,Nvc_content,I_objectID,I_tmID,createtime from space_operation_record where status<>0 and I_operationID=opsid and I_userID=userid ;
select count(*) from sp_tab1 into couid;

set @ihod = 0;
set @listp = '';
set @listpp = '';
set @content0p = '';
set @content0 = '';
while couid > 0 do
select ID,Nvc_content,I_obyuID,createtime,I_tID into @iok,@conuiy,@objiplk,@crtimhr,@tmids from sp_tab1 where ID > @ihod order by ID asc limit 0,1;
if @iok <> '' then
if mname = 'blog' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime) VALUES (@iok,userid,@conuiy,@crtimhr,tikk);
elseif mname = 'team' then
if(@identiftion = 'addblog' || @identiftion = 'mdyblog') then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,I_tmID,createtime) VALUES (@iok,userid,@conuiy,@crtimhr,@tmids,tikk);
else
set @listpp = CONCAT(@listpp,CONCAT(@objiplk,','));
set @operarry1p = substring_index(@conuiy,'|',1);
set @operarry2p = substring_index(@conuiy,'|',-1);
set @content0p = CONCAT(@content0p,CONCAT(@operarry2p,SPACE(1)));
set @objlistp = substring(@listpp,1,length(@listpp)-1);
end if;
elseif mname = 'space' then
if(@identiftion = 'headphoto' || @identiftion = 'status') then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,I_tmID,createtime) VALUES (@iok,userid,@conuiy,@crtimhr,@tmids,tikk);
else
set @listppr = CONCAT(@listppr,CONCAT(@objiplk,','));
set @operarry1pr = substring_index(@conuiy,'|',1);
set @operarry2pr = substring_index(@conuiy,'|',-1);
set @content0pr = CONCAT(@content0pr,CONCAT(@operarry2pr,SPACE(1)));
set @objlistpr = substring(@listppr,1,length(@listppr)-1);
end if;
else
set @listp = CONCAT(@listp,CONCAT(@objiplk,','));
set @operarry1 = substring_index(@conuiy,'|',1);
set @operarry2 = substring_index(@conuiy,'|',-1);
set @content0 = CONCAT(@content0,CONCAT(@operarry2,SPACE(1)));
set @objlist = substring(@listp,1,length(@listp)-1);
end if;
set @ihod = @iok;
end if;
set couid = couid -1;
end while;

if @content0 <> '' then
set @contentp = CONCAT(@operarry1,concat('|',@content0));
Select createtime,ID into @uitimej,@IDjok from space_operation_record where status<>0 and I_operationID=opsid order by createtime desc limit 0,1;
if @uitimej <> '' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime,Nvc_objlist) VALUES(@iok,userid,@contentp,@crtimhr,tikk,@objlist);
end if;
end if;
if @content0p <> '' then
if @identiftion = 'addphoto' then
set @contentp = CONCAT(@operarry1p,CONCAT('|',@content0p));
else
set @contentp = CONCAT(@operarry1p,CONCAT(@content0p,'|'));
end if;

Select createtime,ID into @uitimej,@IDjok from space_operation_record where status<>0 and I_operationID=opsid order by createtime desc limit 0,1;
if @uitimej <> '' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime,Nvc_objlist,I_tmID) VALUES(@iok,userid,@contentp,@crtimhr,tikk,@objlistp,@tmids);
end if;
end if;
if @content0pr <> '' then
set @contentp = CONCAT(@operarry1p,concat('|',@content0pr));
Select createtime,ID into @uitimej,@IDjok from space_operation_record where status<>0 and I_operationID=opsid order by createtime desc limit 0,1;
if @uitimej <> '' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime,Nvc_objlist,I_tmID) VALUES(@iok,userid,@contentp,@crtimhr,tikk,@objlistp,@tmids);
end if;
end if;
delete from sp_tab1;
end if;
end if;

until done end repeat;
close c1;
drop temporary table if exists sp_tab1 ;

UPDATE space_operation_play SET status=0;
UPDATE space_operation_display SET status=0;
Select createtime into @ptimes from space_operation_stat where status<>0 order by createtime desc limit 0,1;
if @ptimes <>'' then
create temporary table if not exists sp_tab2(id bigint(20),Nvc_content MEDIUMTEXT,I_userID bigint(20),I_lyuID bigint(20),D_stattime datetime);
INSERT INTO sp_tab2 Select ID,Nvc_content,I_userID,I_tmID,D_stattime from space_operation_stat where status<>0 and createtime=@ptimes order by D_stattime desc limit 0,30;
select count(*) from sp_tab2 into @cou1id;
set @uoj = 0;
while @cou1id > 0 do
select ID,Nvc_content,I_userID,D_stattime,I_lyuID into @io1k,@conui1y,@objipl1k,@crtimh1r,@unlpa from sp_tab2 where ID > @uoj order by ID asc limit 0,1;
if @io1k <> '' then
INSERT INTO space_operation_play(I_statID,Nvc_content,D_stattime,I_userID,Createtime,I_tmID) VALUES (@io1k,@conui1y,@crtimh1r,@objipl1k,now(),@unlpa);
set @uoj = @io1k;
end if;
set @cou1id = @cou1id -1;
end while;
drop temporary table if exists sp_tab2 ;
end if;

end

Ⅵ mysql 存储过程总结(一)

1、存储过程定义:

存储过程是事先经过编译并存储在数据库中的一段 SQL 语句的集合,调用存储过程可以简化应用开发 人员的很多工作,减少数据在数据库和应用服务器之间的传输,对于提高数据处理的效率是有好处的。 存储过程思想上很简单,就是数据库 SQL 语言层面的代码封装与重用。

2、特点:

封装,复用 : 可以把某一业务SQL封装在存储过程中,需要用到 的时候直接调用即可。

可以接收参数,也可以返回数据 :再存储过程中,可以传递参数,也可以接收返回 值。

减少网络交互,效率提升 : 如果涉及到多条SQL,每执行一次都是一次网络传 输。 而如果封装在存储过程中,我们只需要网络交互一次可能就可以了。

3、基本语法

(1)创建:

(2)调用:

(3)查看:

(4)删除

注意: 在命令行中,执行创建存储过程的SQL时,需要通过关键字 delimiter 指定SQL语句的 结束符。

Ⅶ mysql中存储过程是什么意思

存储过程(stored
procere)是一组为了完成特定功能的sql语句集,经编译后存储在数据库中,用户通过指定存储过程的名字并给定参数(如果该存储过程带有参数)来调用执行它。
一个存储过程是一个可编程的函数,它在数据库中创建并保存。

Ⅷ mysql有存储过程吗

MySQL是有存储过程的。

例子如下:

DELIMITER//
CREATEPROCEDUREmyproc(OUTsint)
BEGIN
SELECTCOUNT(*)INTOsFROMTABLE;
END
//
DELIMITER;

以上!

Ⅸ php调用mysql存储过程,如何实现。 我的代码如下:

mysql存储过程返回2个资源,第一个是执行信息,第二个是存储过程返回结果。

mysql_*系列函数无法获取超过1个资源,需使用mysqli或PDO代替。


PDO:

$stmt=$db->prepare("CALLpro_rb_save(?,?,@return_msg);");
$stmt->bindParam(1,$a);
$stmt->bindParam(2,$b);
$stmt->execute();
$outputArray=$db->query("select@return_msg")->fetch(PDO::FETCH_ASSOC);

var_export($return_msg);
热点内容
明日之后如何扫码登服务器 发布:2025-07-19 20:36:26 浏览:238
ftp搜索引擎工作原理 发布:2025-07-19 20:31:25 浏览:368
景物视频脚本 发布:2025-07-19 20:30:33 浏览:177
hadoop查看文件夹 发布:2025-07-19 20:19:12 浏览:21
安卓手机的旁白在哪里 发布:2025-07-19 20:09:40 浏览:738
身份证注册借书卡的密码是什么 发布:2025-07-19 19:44:39 浏览:75
玩梦幻西游哪个配置好 发布:2025-07-19 19:44:37 浏览:752
php数组大小排序 发布:2025-07-19 19:27:51 浏览:646
linux查找并删除 发布:2025-07-19 19:25:14 浏览:935
linux实验环境 发布:2025-07-19 19:15:09 浏览:410