色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php調(diào)用MySQL存儲過程的方法集合(推薦)

類型一:調(diào)用帶輸入、輸出類型參數(shù)的方法
復(fù)制代碼 代碼如下:
$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ù)的方法
復(fù)制代碼 代碼如下:
$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é)果集的方法
復(fù)制代碼 代碼如下:
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)~~)
復(fù)制代碼 代碼如下:
//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技術(shù)php調(diào)用MySQL存儲過程的方法集合(推薦),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 会同县| 富宁县| 丹寨县| 鄂尔多斯市| 宽城| 灵丘县| 莱州市| 通许县| 神农架林区| 金乡县| 安庆市| 平定县| 蓬溪县| 顺昌县| 环江| 岑溪市| 长兴县| 平武县| 汤原县| 阜新| 杭州市| 贵溪市| 涪陵区| 察哈| 奎屯市| 牙克石市| 镇雄县| 新丰县| 邻水| 获嘉县| 虞城县| 绥中县| 临城县| 南川市| 东乡县| 本溪| 贵溪市| 红安县| 科技| 阿尔山市| 陆良县|