PHP和MySQL存儲(chǔ)過(guò)程的實(shí)例演示

2023-10-12    分類: 網(wǎng)站建設(shè)

以下的文章主要是向大家介紹的是PHP和MySQL存儲(chǔ)過(guò)程的實(shí)例演示,我前兩天在相關(guān)網(wǎng)站看見(jiàn)PHP和MySQL存儲(chǔ)過(guò)程的實(shí)例演示的資料,覺(jué)得挺好,就拿出來(lái)供大家分享。希望在大家往后的學(xué)習(xí)中會(huì)有所幫助。

PHP與MySQL存儲(chǔ)過(guò)程 實(shí)例一:無(wú)參的存儲(chǔ)過(guò)程

					$conn = MySQL_connect('localhost','root','root') or die ("數(shù)據(jù)連接錯(cuò)誤!!!");
MySQL_select_db('test',$conn);
$sql = "create procedure myproce()begin 
 INSERT INTO user (id, username, sex) 
VALUES (NULL, 's', '0');end; ";
MySQL_query($sql);

創(chuàng)建一個(gè)myproce的存儲(chǔ)過(guò)程

$sql = "call test.myproce();";

MySQL_query($sql);

調(diào)用myproce的存儲(chǔ)過(guò)程,則數(shù)據(jù)庫(kù)中將增添一條新記錄。

PHP與MySQL存儲(chǔ)過(guò)程 實(shí)例二:傳入?yún)?shù)的存儲(chǔ)過(guò)程

					$sql = "create procedure myproce2(in score int)
beginif score >= 60 then
select 'pass';elseselect 'no';
end if;end; ";
MySQL_query($sql);

創(chuàng)建一個(gè)myproce2的存儲(chǔ)過(guò)程

$sql = "call test.myproce2(70);"; MySQL_query($sql);

調(diào)用myproce2的存儲(chǔ)過(guò)程,看不到效果,可以在cmd下看到效果。

PHP與MySQL存儲(chǔ)過(guò)程 實(shí)例三:傳出參數(shù)的存儲(chǔ)過(guò)程

					$sql = "create procedure myproce3(out score int)
beginset score=100;end; "; 
 MySQL_query($sql);

創(chuàng)建一個(gè)myproce3的存儲(chǔ)過(guò)程

$sql = "call test.myproce3(@score);"; MySQL_query($sql);

調(diào)用myproce3的存儲(chǔ)過(guò)程

					$result = MySQL_query('select @score;');
$array = MySQL_fetch_array($result); 
 echo '<pre>';print_r($array); 
PHP與MySQL

存儲(chǔ)過(guò)程 實(shí)例四:傳出參數(shù)的inout存儲(chǔ)過(guò)程

					$sql = "create procedure myproce4(inout sexflag int)
beginSELECT * FROM user 
WHERE sex = sexflag;end; ";
MySQL_query($sql);

創(chuàng)建一個(gè)myproce4的存儲(chǔ)過(guò)程

$sql = "set @sexflag = 1"; MySQL_query($sql); 設(shè)置性別參數(shù)為1

$sql = "call test.myproce4(@sexflag);"; MySQL_query($sql);

調(diào)用myproce4的存儲(chǔ)過(guò)程,在cmd下面看效果

網(wǎng)站標(biāo)題:PHP和MySQL存儲(chǔ)過(guò)程的實(shí)例演示
分享地址:http://www.bm7419.com/news49/285699.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、標(biāo)簽優(yōu)化網(wǎng)站制作、品牌網(wǎng)站建設(shè)、外貿(mào)建站、網(wǎng)站收錄

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)