Home > Article > Backend Development > put your head on my shoulder Use PHP to call the stored procedure of the database!
Use PHP to call the stored procedure of the database!
Author: fox4000
Yesterday, I saw a comrade asking if the stored procedure could be called using php. I felt that it should be possible, so I immediately conducted the experiment and it was very successful! Very unexpected! Therefore, write it down for everyone’s reference!
As we all know, a stored procedure is a script program on the server side, which is very fast to execute, but it also has a disadvantage, that is, it relies on a fixed database and has poor portability!
In my last article, I mentioned that you can use COM components to access ado and related components. Whether you build it yourself or come with the system, you can expand the functions of the system, but now php does not support dcom/com+, but I believe it The next version should be supported.
Not much to say, let’s try it right away.
The following is a simple storage procedure of mine
CREATE PROCEDURE [sp_mystoreprocedure] AS
select companyname, contactname, city from customers
Actually, you can also write more complex ones, but unfortunately I don’t study this deeply, so I have to keep it simple!
The following 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 |
---|---|---|
'; print $fld0- >value; print ' | '; print $fld1->value; print ' | ';
The above introduces the storage process of putting your head on my shoulder using PHP to call the database! , including the content of putting your head on my shoulder. I hope it will be helpful to friends who are interested in PHP tutorials.