PHP call oracle,mysql,mssql Server stored procedure method _php Tutorial

Source: Internet
Author: User
Tags mssql server mysql tutorial
Here is a summary of three popular database tutorials on how to use PHP tutorials to invoke their stored procedures, we have a MySQL tutorial, Oracle,mssql server Oh.

function Check_login ($user, $pass) {
$conn = Ocilogon (' user ', ' Pass ', ' database ');
$sql = ' Begin:result: = Test.check_login (: User,:p); end; ';
$stmt = Oci_parse ($conn, $sql);

$result = ";
Oci_bind_by_name ($stmt, ': User ', $user, 32);
Oci_bind_by_name ($stmt, ':p-up ', MD5 ($pass), 32);
Oci_bind_by_name ($stmt, ': Result ', $result, 10);
Oci_execute ($stmt);
Ocilogoff ($conn);

return $result;
}
?>

Call MySQL

The stored procedure is changed to:
CREATE PROCEDURE in_out (in UID int) begin
Set @msg = ' Hello ';
SELECT *, @msg from manage_loginhistory where H_uid=uid;
End
PHP Call changed to:
$sql = "Call In_out (39)";
$rs =mysql_query ($sql);
$row =mysql_fetch_array ($RS);

Call MS SQL Server

$user _name = ' Tears of the Dragon '; Declares a variable that is used as the input parameter of a stored procedure
$password = ' 123456 '; Then declare a variable to be used as another input parameter of the stored procedure
$info = "; $info, to accept parameter values from stored procedure output
$host = "192.168.0.1"; Defining the database server
$user = "sa"; Connect User Name
$password = "123456"; Connection password
$DB = "Sample"; Database name
$dblink =mssql_connect ($host, $user, $password) or Die ("can ' t connect to MSSQL"); Connecting to the database server
mssql_select_db ($db, $dblink) or Die ("Can ' t select Sample");//Select Database

$SP = Mssql_init ("test"); Initialize a stored procedure

Add a parameter to the stored procedure, @user_name the parameter name, $user _name the PHP variable that corresponds to the argument, Sqlvarchar indicates that the parameter type is a varchar type of SQL Server, and the first false indicates that the parameter is not an output parameter. That is, the argument is an input parameter, and the second false indicates that the parameter is not allowed to be null, and the last 30 indicates that the variable has a length of 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); Add an output parameter to a stored procedure
Mssql_execute ($SP); Execute the stored procedure

Echo $info; Prints out the output parameter values returned from the stored procedure

http://www.bkjia.com/PHPjc/630764.html www.bkjia.com true http://www.bkjia.com/PHPjc/630764.html techarticle here is a summary of three popular database tutorials on how to use PHP tutorials to invoke their stored procedures, we have a MySQL tutorial, Oracle,mssql server Oh. php function Check_login ($use ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.