Use PHP to call the database storage process !. Use PHP to call the database storage process! Author: fox4000 yesterday, I saw a comrade-in-arms asking if the stored procedure can be called using php. I felt that it was okay. so I immediately started an experiment to call the stored procedure of the database using PHP!
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'
| Directive |
Local Value |
Master Value |
';While (! $ Rs-> EOF ){$ I + = 1;$ Fld0 = $ rs-> Fields (0 );$ Fld1 = $ rs-> Fields (1 );$ Fld2 = $ rs-> Fields (2 );Print'
'; Print $ fld0-> value; Print'
|
'; Print $ fld1-> value; Print' |
'; Print $ fld2-> value; Print' |
';$ Rs-> MoveNext ();}Print'
';
$ 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!
Success! Author: fox4000 yesterday, I saw a comrade-in-arms asking if the stored procedure can be called using php. I felt that it was okay. so I immediately conducted an experiment...