本文实例讲述了PHP使用PDO调用mssql存储过程的方法。分享给大家供大家参考,具体如下:
数据库中已创建存储过程user_logon_check, PHP调用示例如下,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
<?php
$dsn = 'mssql:dbname=MyDbName;host=localhost' ;
$user = 'sa' ;
$password = '666666' ;
try {
$dbCon = new PDO( $dsn , $user , $password );
} catch (PDOException $e ) {
print 'Connection failed: ' . $e ->getMessage();
exit ;
}
$username = '123' ;
$userpsw = '123' ;
// $xp_userlogon = $dbCon ->query( "exec user_logon_check '$username','$userpsw'" );
//mysql->call user_logon_check( '$username' , '$userpsw' );
//mysql->call user_logon_check(?,?)
$xp_userlogon = $dbCon ->prepare( 'exec user_logon_check ?,?' );
$xp_userlogon ->bindParam(1, $username );
$xp_userlogon ->bindParam(2, $userpsw );
$xp_userlogon ->execute();
$uCol = $xp_userlogon ->columnCount();
echo $uCol . "<br>" ;
while ( $row = $xp_userlogon ->fetch()){
for ( $i =0; $i < $uCol ; $i ++ )
print $row [ $i ]. " " ;
print "<br>" ;
}
?>
|
希望本文所述对大家PHP程序设计有所帮助。
原文链接:http://blog.csdn.net/hqulyc/article/details/5587167