MySQL儲存過程的建立和呼叫

2021-08-18 23:45:51 字數 1871 閱讀 9249

--  建立

delimiter //

create procedure authenti(in p1 varchar(32), in p2 varchar(32), in p3 varchar(32), in p4 varchar(45), out p5 int)

begin

-- 許可權檢查

-- by wuzude 2018-01-22 ver 1.0

declare rawsum int(1) default 0;   -- 行計數器

declare projid int(4) default 0;   -- 專案id

declare intfcid int(4) default 0;  -- 介面id

set p5 = 0;

-- 取得有效的專案id和介面id,對行計數

select count(pi_id), proj_id, intfc_id into rawsum, projid, intfcid

from proj_intfc

where proj_id = (select proj_id from proj where ename = p1 and valid = 1)

and intfc_id = (select intfc_id from intfc where ename = p2 and valid = 1)

and valid = 1;

-- select rawsum,projid,intfcid;

if rawsum = 1 then

set rawsum = 0;

and valid = 1

and ((unix_timestamp(now()) * 1000) < expiretime or remain_num > 0);

if rawsum = 1 then

set rawsum = 0;

select count(power_id) into rawsum

from  power_proj

and   proj_id = projid

and   valid = 1;

if rawsum = 1 then

set rawsum = 0;

select count(power_id) into rawsum

from power_intfc

and intfc_id = intfcid

and valid = 1;

if rawsum = 1 then

set p5 = 1;

end if;

end if;

end if;

end if;

select p5;

end //

delimiter ;

-- 在phpmyadmin中呼叫

-- 出參必須使用乙個變數接住

// 在php中呼叫

if($t->authenti($sql, "p5"))

public function authenti($sql, $tag)

$resource = $cn->query($sql);

if($resource === false)

$result = $this->obj2arr(mysqli_fetch_array($resource, mysqli_both));  //轉陣列

mysqli_free_result($resource);

$cn->close();

//return $result;

if(!isset($result[$tag]))

if($result[$tag] != 1)

return true;

}

MySQL儲存過程的建立和呼叫

mysql儲存過程弱爆了。下面這個建立 任何地方不匹配都報錯,包括空格!delimiter begin 許可權檢查 by wuzude 2018 01 22 ver 1.0 declare rawsum int 1 default 0 行計數器 declare projid int 4 defaul...

MYSQL儲存過程的建立和呼叫

建立儲存過程 建立過程呼叫 create procedure sp name proc parameter characteristics routine bodycreate procedure 為用來建立儲存函式的關鍵字 sp name為儲存過程的名稱 proc parameter為指定儲存過程...

儲存過程的 建立 和 呼叫

1 建立儲存過程has permission create or replace procedure has permission contentid in varchar2,contenttype in number,privilege in number,userid in number,ret...