Teach you to use Oracle Database in PHP (i)
In PHP, PHP contains almost all of the current database processing functions, including Oracle, and in this article we show you how to use these functions to manipulate the Oracle database.
PHP provides 2 large classes of APIs (application interfaces) to manipulate Oracle databases. One is the standard Oracle processing function (ORA) and the other is the Oracle 8 call interface function (OCI8). The latter can only be used on Oracle version 7 or 8. Since OCI8 offers many optimization options, the OCI8 interface should be used whenever possible. Here we illustrate each of these two sets of functions.
First of all, the premise of this article assumes that you have installed the Oracle database environment and the PHP development environment. If you do not understand and do not have much to do with the internet has a lot of relevant good articles can be consulted.
First step: Create an experimental database
This question you can ask your database administrator or refer to the Oracle User manual for processing, here no more talk
Set up a data sheet with ORA
Even if you have already created the datasheet, take a look at this paragraph of text as well. It can show you how to operate Oracle with PHP+SQL technology.
In this example, we created a data table for storing personal email.
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 work with Oracle databases, we will first establish a junction with Oracle.
The syntax is ora_logon (user, password), which returns a Connectid.
Reminder: Before we do this we must also set the environment variable: ORACLE_SID value.
We can now interactively manipulate Oracle through the ID of the junction. The data sheet name is called Email_info. The table consists of 2 domains, one storing the personal name, (for example: ARIA) a storage email address such as (xiaoyue@163.net)
A cursor Ora_open is also required. This cursor is often used to enumerate data. We use Ora_parse or ora_exec to query the result set of Oracle. Ora_parse the correctness of SQL syntax and ora_exec executes the corresponding SQL statement. If all this works, then we'll run ora_commit to confirm.
The above describes the teaching you to use the Oracle database in PHP (a), including aspects of the content, you want to be interested in PHP tutorial friends helpful.