Use PHP to call the database storage process!
Author: fox4000
Yesterday, I saw a comrade-in-arms asking if I could use php to call the storage process. I thought it was okay. So I started the experiment right away and it was very successful! Beyond my expectation! Therefore, write it for your reference!
As you know, the stored procedure is a script program on the server, which runs very quickly. However, it also has a disadvantage: It depends on a fixed database and has poor portability!
In my previous article, I mentioned that the com component can be used to access ado and related components. Both self-built and system-carried components can be used to expand the system functions, but now php does not support dcom/com +, but I believe its next version should support it.
Let's try it now.
Below is my simple storage process
Create procedure [sp_mystoreprocedure]
Select companyname, contactname, city from MERs
In fact, it can be complicated to write. Unfortunately, I did not have a deep research on this, so I had to take it easy!
Below is my PHP File
<?
Define ("OLEDB_CONNECTION_STRING ",
"Provider = SQLOLEDB; Data Source = zzb; Initial Catalog = Northwind; User ID = sa; Password = ");
$ Dbc = new COM ("ADODB. Connection ");
$ Dbc-> Open (OLEDB_CONNECTION_STRING );
$ Command = "sp_mystoreprocedure ";
$ Rs = $ dbc-> Execute ($ command); // Recordset
$ I = 0;
Echo '<table cellSpacing = "1" cellPadding = "3" width = "600" align = "center" bgColor = "#000000" border = "0">
<Tr vAlign = "bottom" bgColor = "# 9999cc">
<Th> Directive </th>
<Th> Local Value </th>
<Th> Master Value </th>
</Tr> ';
While (! $ Rs-> EOF ){
$ I + = 1;
$ Fld0 = $ rs-> Fields (0 );
$ Fld1 = $ rs-> Fields (1 );
$ Fld2 = $ rs-> Fields (2 );
Print '<tr vAlign = "baseline" bgColor = "# cccccc">
<Td bgColor = "# ccccff"> <B> ';
Print $ fld0-> value;
Print '</B> <br> </td>
<Td align = "middle"> ';
Print $ fld1-> value;
Print '</td> <td align = "middle"> ';