PHP call the stored procedures of Oracle, mysql, and mssqlserver _ PHP Tutorial

Source: Internet
Author: User
Tags mssql server mssqlserver mysql tutorial
PHP calls the stored procedures of Oracle, mysql, and mssqlserver. The following summarizes three popular database tutorials: how to use the php Tutorial to call their stored procedures. we will talk about the mysql tutorial, oracle, and mssqlserver .? Phpfunctioncheck_login ($ use below summarizes three popular database tutorials on how to use php tutorials to call their stored procedures. we will talk about mysql tutorials, oracle, and mssql server.

Function check_login ($ user, $ pass ){
$ Conn = ocilogon ('user', 'pass', 'database ');
$ SQL = 'In in: 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;
}
?>

Call mysql

Change the stored procedure:
Create procedure in_out (in uid int) begin
Set @ msg = 'hello ';
Select *, @ msg from manage_loginhistory where h_uid = uid;
End;
Php call changed:
$ SQL = "call in_out (39 )";
$ Rs = mysql_query ($ SQL );
$ Row = mysql_fetch_array ($ rs );

Call ms SQL server

$ User_name = 'Tears of the Dragon '; // declare a variable and use it as the input parameter of the stored procedure.
$ Password = '000000'; // declare another variable and use it as another input parameter of the stored procedure.
$ Info = ''; // $ info, used to accept the parameter values output from the stored procedure
$ Host = "192.168.0.1"; // defines the database server
$ User = "sa"; // connection username
$ Password = "123456"; // connection password
$ Db = "sample"; // database name
$ Dblink = mssql_connect ($ host, $ user, $ password) or die ("can't connect to mssql"); // connect to the database server
Mssql_select_db ($ db, $ dblink) or die ("can't select sample"); // select a database

$ Sp = mssql_init ("test"); // initialize a stored procedure

// Add a parameter for the stored procedure. @ user_name is the parameter name, $ user_name is the php variable corresponding to the parameter, and sqlvarchar indicates that the parameter type is the varchar type of SQL server, the first false indicates that this parameter is not an output parameter, that is, this parameter is an input parameter. the second false indicates that this parameter cannot be null, and the last 30 indicates that the variable length is 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 for the stored procedure
Mssql_execute ($ sp); // execute the stored procedure

Echo $ info; // Print the output parameter values returned from the stored procedure

To call their stored procedures, we will talk about mysql tutorials, oracle, and mssql server. ? 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.