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, you can write more complex, but 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"> ';
Print $ fld2-> value;
Print '</td> </tr>'; $ rs-> MoveNext ();
}
Print '</TABLE>'; $ rs-> Close ();
?> Note that your server must be enabled! In addition, the name of the stored procedure cannot be entered incorrectly. Otherwise, a fatal error will occur, and you do not know where the error is. This is the poor processing of the PHP file, but I believe it will be improved in the future. I have been learning php for a long time, but it is not that easy to make good use of it, but it is indeed beyond my imagination. Some things are really amazing, don't know. It's amazing to use it! (Source: Viphot)