以下的文章主要是向大家介绍的是PHP和MySQL存储过程的实例演示,我前两天在相关网站看见PHP和MySQL存储过程的实例演示的资料,觉得挺好,就拿出来供大家分享。希望在大家今后的学习中会有所帮助。
PHP与MySQL存储过程 实例一:无参的存储过程
<ccid_code>$conn = MySQL_connect('localhost','root','root') or die ("数据连接错误!!!"); MySQL_select_db('test',$conn); $sql = " create procedure myproce() begin INSERT INTO user (id, username, sex) VALUES (NULL, 's', '0'); end; "; MySQL_query($sql);</ccid_code> |
创建一个myproce的存储过程
$sql = "call test.myproce();";
MySQL_query($sql);
调用myproce的存储过程,则数据库中将增加一条新记录。
PHP与MySQL存储过程 实例二:传入参数的存储过程
<ccid_code>$sql = " create procedure myproce2(in score int) begin if score >= 60 then select 'pass'; else select 'no'; end if; end; "; MySQL_query($sql);</ccid_code> |
创建一个myproce2的存储过程
$sql = "call test.myproce2(70);"; MySQL_query($sql);
调用myproce2的存储过程,看不到效果,可以在cmd下看到结果。
PHP与MySQL存储过程 实例三:传出参数的存储过程
<ccid_code>$sql = " create procedure myproce3(out score int) begin set score=100; end; "; MySQL_query($sql);</ccid_code> |
创建一个myproce3的存储过程
$sql = "call test.myproce3(@score);"; MySQL_query($sql);
调用myproce3的存储过程
<ccid_code>$result = MySQL_query('select @score;'); $array = MySQL_fetch_array($result); echo '<pre class="brush:php;toolbar:false">';print_r($array); PHP与MySQL |
存储过程 实例四:传出参数的inout存储过程
<ccid_code>$sql = " create procedure myproce4(inout sexflag int) begin SELECT * FROM user WHERE sex = sexflag; end; "; MySQL_query($sql);</ccid_code> |
创建一个myproce4的存储过程
$sql = "set @sexflag = 1"; MySQL_query($sql); 设置性别参数为1
$sql = "call test.myproce4(@sexflag);"; MySQL_query($sql);
调用myproce4的存储过程,在cmd下面看效果

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SublimeText3 Linux新版
SublimeText3 Linux最新版

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。