PHP calls three database methods (3). Read the PHP call methods for three databases (3). Oracle is the most popular relational database in the world. It is a powerful engine of industrialization promoted by large companies. Let's take a look at the related functions: (1) integerora_logon (stringuser, stringpassword) start an Oracle data ">
Oracle is the most popular relational database in the world. It is a powerful engine of industrialization promoted by large companies. Let's first look at its related functions:
(1) integer ora_logon (string user, string password)
Start the connection to an Oracle database server.
(2) integer ora_open (integer connection)
Open the cursor of the given connection.
(3) integer ora_do (integer connection, string query)
Execute the query on the given connection. PHP generates an indicator, parses the query, and executes it.
(4) integer ora_parse (integer cursor, string query)
Parse a query and prepare it for execution.
(5) boolean ora_exec (integer cursor)
Execute a query previously parsed by the ora_parse function.
(6) boolean ora_fetch (integer cursor)
This function causes the rows in a executed query to be taken into the indicator. This allows you to call the ora_getcolumn function.
(7) string ora_getcolumn (integer cursor, integer column)
Returns the current value. A numeric index with a column starting from zero.
(8) boolean ora_logoff (integer connection)
Disconnect the database server.
The following is an example program for inserting data into an ORACLE database:
Insert data to an ORACLE database
// Set two environment variables ORACLE_HOME and ORACLE_SID first
Putenv ("ORACLE_HOME =/oracle/app/oracle/product/8.0.4 ");
Putenv ("ORACLE_SID = ora8 ");
// Set Chinese characters for the webpage
Putenv ("NLS_LANG = Simplified_Chinese.zhs16cgb231280 ");
If ($ connection = ora_logon ("scott", "tiger ")){
// The database table test has three items: ID, name, and Description.
$ SQL = 'Insert into test (ID, name, Description) values ';
$ SQL. = '(''. $ ID.'', ''. $ name.'', ''. $ Description .'')';
If ($ cursor = ora_do ($ connect, $ SQL )){
Print ("insert finished! ");
}
$ Query = 'select * from test ';
If ($ cursor = ora_do ($ connect, $ query )){
Ora_fetch ($ cursor );
$ Content0 = ora_getcolumn ($ cursor, 0 );
$ Content1 = ora_getcolumn ($ cursor, 1 );
$ Content2 = ora_getcolumn ($ cursor, 2 );
Print ("$ content0 ");
Print ("$ content1 ");
Print ("$ content2 ");
Ora_close ($ cursor );
}
Ora_logoff ($ connection );
}
?>