Use PHP to call the database storage process! (reprint) believe that you in the WIN32 with PHP friends found that the original use of WIN32 also have this benefit oh. ...

Source: Internet
Author: User
Tags learn php php file win32
Process | data | Database use PHP to call the database storage process!
Author: fox4000

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" >
&LT;TD bgcolor= "#ccccff" ><b>;
Print $FLD 0->value;
print ' </b><br></td>
&LT;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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.