PHP Method Example for Calling mssql Stored Procedures Using PDO
- 2021-08-10 07:07:27
- OfStack
This article illustrates how PHP uses PDO to call mssql stored procedures. Share it for your reference, as follows:
The stored procedure user_logon_check has been created in the database, and the example of PHP call is as follows.
<?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>";
}
?>
For more readers interested in PHP related contents, please check the topics on this site: "Summary of PHP Database Operation Skills Based on pdo", "Summary of php+Oracle Database Programming Skills", "Encyclopedia of PHP+MongoDB Database Operation Skills", "Introduction to php Object-Oriented Programming", "Summary of php String (string) Usage", "Introduction to php+mysql Database Operation Skills" and "Summary of php Common Database Operation Skills"
I hope this article is helpful to everyone's PHP programming.