Use PHP to call the database storage process!
Author: fox4000
Yesterday, see a comrade asked if you can use PHP to call the storage process, the feeling should be able to, so, immediately carried out the experiment, very successful! It was a very unexpected surprise to me! Therefore, write out, for everyone to reference!
As you know, the stored procedure is a script on the server side, the execution speed is very fast, but it also has a disadvantage, is to rely on a fixed database, portability is not good!
My last article, mentioned that with COM components can access ADO and related components, whether it is built or the system with, can extend the functionality of the system, but now PHP does not support dcom/com+, but believe that its next version should be supported.
Don't say so much, let's try it right away.
Here's a simple storage process for me.
CREATE PROCEDURE [Sp_mystoreprocedure] As
Select CompanyName, ContactName, city from customers
In fact, can also write more complex, but I am not deep on this study, had to take the simple!
Here 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; $fld 0 = $rs->fields (0); $fld 1 = $rs->fields (1); $FLD 2 = $rs->fields (2); print '
'; Print $FLD 0->value; print '
|
'; Print $FLD 1->value; print ' |
'; Print $FLD 2->value; print ' |
'; $rs->movenext (); } print '
';
$rs->close ();
?>
Note that your server must be turned on! In addition, the name of the stored procedure cannot be written incorrectly. Otherwise it will be out of the fatal error, and, you do not know the error is there, this is the PHP file bad for error handling, but I believe it will be improved later.
I have been learning PHP for a long time, but found to really use it, not so easy, but it is also beyond my imagination, some things really wonderful, really, do not know, a use really wonderful!
The above describes the put your head on my shoulder using PHP to call the database storage process! , including put your head on my shoulder, I want to be interested in PHP tutorial friends helpful.