Process | data | database
Yesterday, saw a comrade asked if you can use PHP to call the storage process, the feeling should be can, so, immediately carried out the experiment, very successful! It's so unexpected! So, write it out, for everyone's reference!
As you know, stored procedures are on the server side of a script program, the execution is fast, but it also has a disadvantage, is dependent on a fixed database, transplant is not good!
My last article, mentioned that the use of COM components can access ADO and related components, whether built or 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 talk 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 in this study, had to take 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 ' <table cellspacing= "1" cellpadding= "3" width= "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;
$FLD 0 = $rs->fields (0);
$FLD 1 = $rs->fields (1);
$FLD 2 = $rs->fields (2);
print ' <tr valign= "baseline" bgcolor= "#cccccc" >
<TD bgcolor= "#ccccff" ><b>;
Print $FLD 0->value;
print ' </b><br></td>
<TD align= "Middle" >;
Print $FLD 1->value;
print ' </td><td align= ' middle ' > ';
Print $FLD 2->value;
print ' </td></tr> ';
$rs->movenext ();
}
print ' </TABLE> ';
$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 a fatal error, and, you do not know where the error is, this is the PHP file on the bad treatment, but I believe it will be improved.
I have to learn PHP for a long time, but found that 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!