发布于 2015-01-02 12:35:29 | 202 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Mysql教程,程序狗速度看过来!

Mysql关系型数据库管理系统

MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQL AB公司。MySQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库。


本文为大家整理总结是示例是php调用MySQL存储过程的方法集锦,感兴趣的同学参考下。


类型一:调用带输入、输出类型参数的方法


$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; //输出来自存储过程中输出的变量


类型二:调用带多个输出类型和多个输入类型参数的方法


$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


类型三:调用带返回结果集的方法


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']; //输出数据集
 }

} catch ( Exception $e ) {
 echo $e;
}


类型四:调用带返回多个结果集的方法(目前只能通过mysqli来实现~~)


//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 ……
……


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务