PHP programs access the database and can use stored procedures completely, and some people think that using stored procedures is easy to maintain. But, benevolent see, on this issue, I think the use of stored procedures means that DBAs and developers need to work more closely together, and if one of them is notconsistent, it is obviously difficult to maintain.
But there are at least two of the most obvious advantages of using stored procedures: speed and efficiency. The speed of using stored procedures is obviously faster. In efficiency, if the application needs to do a series of SQL operations at a time, you need to go to PHP and Oracle, instead of putting the application directly to the database side to reduce the number of round trips and increase efficiency. However, in Internet applications, speed is extremely important, so it is necessary to use stored procedures. I also use PHP to call the stored procedure shortly, to do the following as a dummy.
Create a test table CREATE TABLE test ( ID number (+) not null, NAME VARCHAR2 (+) not null, PRIMARY KEY (ID));//Inserts a data insert INTO TEST VALUES (5, ' php_book ');//Create a stored procedure create OR REPLACE PROCEDURE proc_test ( p_ ID in Out number, p_name out VARCHAR2) as BEGIN SELECT name into P_name from TEST WHERE ID = 5; END proc_test;/
PHP Code:
<?php//Establish database connection $user = "Scott"; Database user name $password = "Tiger"; Password $conn_str = "Tnsname"; Connection string (cstr:connection_string) $remote = TRUE//Whether remote connect if ($remote) {$conn = Ocilogon ($user, $password, $conn _str);} else {$conn = Ocilogon ($user, $password);} Set binding $id = 5; Prepare the PHP variable to bind id$name = ""; Prepare the PHP variable to bind name/** the SQL statement (sql_sp:sql_storeprocedure) * syntax that invokes the stored procedure (*): * BEGIN stored procedure name ([[:] parameter]); END; * Plus a colon indicates that the parameter is a location **/$sql _sp = "BEGIN proc_test (: ID,: name); END; "; /parse$stmt = Ociparse ($conn, $sql _sp);//Execute Binding ocibindbyname ($stmt, ": id", $id, 16); Parameter description: Bind PHP variable $id to location: ID, and set binding length of 16 bit ocibindbyname ($stmt, ": Name", $name,);//executeociexecute ($stmt);//Result echo " Name is: $name <br> ";?