php調(diào)用MySQL存儲過程的方法集合_PHP教程
推薦:解決PHP mysql_query執(zhí)行超時(Fatal error: Maximum execution time …)【錯誤原因】: mysql_query執(zhí)行超時. 【解決辦法】: 修改php.ini中的 max_execution_time的值,默認(rèn)為300,單位是秒,例如: ;max_execution_time = 300 ;將其改為: max_execution_time = 3000 最后,重新啟動服務(wù)管理器即可~
本篇文章是對php調(diào)用MySQL存儲過程的方法進(jìn)行了集合與匯總,需要的朋友參考下類型一:調(diào)用帶輸入、輸出類型參數(shù)的方法
$returnValue = '';
try {
mysql_query ( "set @Return" );
$spname = 'P__Test_GetInfo1';
mysql_query ( "call $spname(@Return, '{$userId}', '{$pwd}')" ) or die ( "[$spname]Query failed:" . mysql_error () );
$result_return = mysql_query ( "select @Return" );
$row_return = mysql_fetch_row ( $result_return );
$returnValue = $row_return [0];
} catch ( Exception $e ) {
echo $e;
}
echo $returnValue; //輸出來自存儲過程中輸出的變量
類型二:調(diào)用帶多個輸出類型和多個輸入類型參數(shù)的方法
$userId = 0;
try{
mysql_query("set @Message");
mysql_query("set @Id");
mysql_query("call P__Test_Login(@Message, @Id, '{$userId}', '{$pwd}')", $conn) or die("Query failed:".mysql_error());
$result_mess = mysql_query("select @Message");
$result_uid = mysql_query("select @Id");
$row_mess = mysql_fetch_row($result_mess);
$row_uid = mysql_fetch_row($result_uid);
$Proc_Error = $row_mess[0];
$uId = $row_uid[0];
}
catch( Exception $e )
{
echo $e;
}
echo 'proc return message:'$Proc_Error.'<br/>'; //輸出來自存儲過程中輸出的變量
echo 'User id:'.$uId; //獲取用戶id
類型三:調(diào)用帶返回結(jié)果集的方法
try {
$spname = 'P__Test_GetData';
$query = mysql_query ( "call $spname()", $conn ) or die ( "[$spname]Query failed:".mysql_error() );
while ( $row = mysql_fetch_array ( $query ) ) {
echo $row ['ProvinceID'].'::'.$row ['ProvinceName']; //輸出數(shù)據(jù)集
}
} catch ( Exception $e ) {
echo $e;
}
類型四:調(diào)用帶返回多個結(jié)果集的方法(目前只能通過mysqli來實現(xiàn)~~)
//PHP
$rows = array ();
$db = new mysqli($server,$user,$psd,$dbname);
if (mysqli_connect_errno()){
$this->message('Can not connect to MySQL server');
}
$db->query("SET NAMES UTF8");
$db->query("SET @Message");
if($db->real_query("call P__Test_GetData2(@Message)")){
do{
if($result = $db->store_result()){
while ($row = $result->fetch_assoc()){
array_push($rows, $row);
}
$result->close();
}
}while($db->next_result());
}
$db->close();
print_r($rows);
//Procedure
……
select * from T1 where ……
select * from T2 where ……
……
分享:PHP 文件編程綜合案例-文件上傳的實現(xiàn)PHP文件上傳 1、upload.php 復(fù)制代碼 代碼如下: !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN html head titleddd/title meta http-equiv=content-type content=text/html; charset=UTF-8 /head body !--文件上傳要注意:1、要有enctyp,2、method=pos
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁面代碼執(zhí)行時間
- PHP中獎概率的抽獎算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問控制的和運算符優(yōu)先級介紹
- 關(guān)于PHP語言構(gòu)造器介紹
- php/js獲取客戶端mac地址的實現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國語言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
- 相關(guān)鏈接:
- 教程說明:
PHP教程-php調(diào)用MySQL存儲過程的方法集合
。