PHP調用Oracle,mysql,mssql server 儲存過程方法_PHP教程

來源:互聯網
上載者:User
下面總結了三種流行的資料庫教程如何利用php教程 來調用它們的預存程序,我們講有mysql教程,oracle,mssql server哦。

function check_login($user, $pass) {
$conn = ocilogon('user', 'pass', 'database');
$sql = 'begin :result := test.check_login(:user, :pass); end;';
$stmt = oci_parse($conn, $sql);

$result = '';
oci_bind_by_name($stmt, ':user', $user, 32);
oci_bind_by_name($stmt, ':pass', md5($pass), 32);
oci_bind_by_name($stmt, ':result', $result, 10);
oci_execute($stmt);
ocilogoff($conn);

return $result;
}
?>

調用mysql

預存程序改成:
create procedure in_out(in uid int) begin
set @msg='hello';
select *,@msg from manage_loginhistory where h_uid=uid;
end;
php調用改成:
$sql = "call in_out(39)";
$rs=mysql_query($sql);
$row=mysql_fetch_array($rs);

調用ms sql server

$user_name = '龍之淚'; //聲明一個變數,用做預存程序的輸入參數
$password = '123456'; //再聲明一個變數,用做預存程序的另一個輸入參數
$info = ''; //$info,用來接受從預存程序輸出的參數值
$host="192.168.0.1"; //定義資料庫伺服器
$user="sa"; //串連使用者名稱
$password="123456"; //串連密碼
$db="sample"; //資料庫名稱
$dblink=mssql_connect($host,$user,$password) or die("can't connect to mssql"); //串連資料庫伺服器
mssql_select_db($db,$dblink) or die("can't select sample");//選擇資料庫

$sp = mssql_init("test"); //初始化一個預存程序

//為預存程序添加一個參數,@user_name為參數名,$user_name為參數對應的php變數,sqlvarchar表明該參數類型為sql server的varchar類型,第一個false表示該參數不是輸出參數,即該參數是輸入參數,第二個false表示該參數不允許為null,最後的30表示該變數的長度為30
mssql_bind($sp,"@user_name",$user_name,sqlvarchar,false,false,30);
mssql_bind($sp,"@password",$password,sqlvarchar,false,false,30);
mssql_bind($sp,"@info",$info,sqlvarchar,true,false,30); //為預存程序添加一個輸出參數
mssql_execute($sp); //執行該預存程序

echo $info; //列印出從預存程序中返回的輸出參數值

http://www.bkjia.com/PHPjc/630764.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/630764.htmlTechArticle下面總結了三種流行的資料庫教程如何利用php教程 來調用它們的預存程序,我們講有mysql教程,oracle,mssql server哦。 ?php function check_login($use...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.