In php3.0 and later versions, php has nearly all of the current database processing functions, including Oracle. in this article, we use an instance to first apply these functions to control the Oracle database. PHP provides two types of APIs (using program interfaces)
In php3.0 and later versions, php has nearly all of the current database processing functions, including Oracle. in this article, we use an instance to first apply these functions to control the Oracle database.
PHP provides two types of APIs (using program interfaces) to control Oracle databases. One is the scale Oracle processing function (ORA) and the other is the Oracle 8 calling interface function (OCI8). The latter can only be applied in Oracle 7 or 8 versions. Because OCI8 provides many optimization options, the OCI8 interface should be used whenever possible. Here we use these two function sets for demonstration.
First, the condition in this article assumes that you have installed the Oracle database environment and the PHP development environment. if you do not understand it, it doesn't matter much. There are many related articles on the Internet for reference.
Step 1: Create an experimental database
For this title, you can ask your database administrator or refer to the Oracle User manual for processing.
Create a data table with ORA
Even if you have created a data table, take a look at the text section. It tells you how to use php SQL to control Oracle
In this example, we create a data table for personal email storage.
Related PHP code:
PutEnv ('Oracle _ SID = orasid ');
$ Connection = Ora_Logon ('username', 'password ');
If ($ connection = false ){
Echo Ora_ErrorCode ($ connection). ':'. Ora_Error ($ connection ).'';
Exit;
}
$ Cursor = Ora_Open ($ connection );
If ($ cursor = false ){
Echo Ora_ErrorCode ($ connection). ':'. Ora_Error ($ connection ).'';
Exit;
}
$ Query = 'create table email_info '.
'(Fullname varchar (255), email_address varchar (255 ))';
$ Result = Ora_Parse ($ cursor, $ query );
If ($ result = false ){
Echo Ora_ErrorCode ($ cursor). ':'. Ora_Error ($ cursor ).'';
Exit;
}
$ Result = Ora_Exec ($ cursor );
If ($ result = false ){
Echo Ora_ErrorCode ($ cursor). ':'. Ora_Error ($ cursor ).'';
Exit;
}
Ora_Commit ($ connection );
Ora_Close ($ cursor );
Ora_Logoff ($ connection );
?>
To process the Oracle database, we must first establish a connection with Oracle.
The syntax is Ora_Logon (user, password). return a connectID ..
Tip: before that, we must set the value of the environment variable ORACLE_SID.
Now, we can use the join ID to perform interactive control over Oracle. The data table name is email_info. The table consists of two domains, one for storing the full name of the individual, (for example: Xiaoyue) one for storing the e-mail address such as (xiaoyue@163.net)
You also need a cursor Ora_Open. This cursor is often used to enumerate data. We use Ora_Parse or Ora_Exec to query the Oracle result set. Ora_Parse to verify the SQL syntax accuracy, while Ora_Exec executes the corresponding SQL statement. If all the operations are normal, we will run Ora_Commit to confirm.
Create A Table Using OCI
Next we will create an email personal information book. This time the OCI8 API command is used
Related PHP code:
PutEnv ('Oracle _ SID = orasid ');