Start looking for PHP in the online operation of the Oracle method class ~ Sure enough to find a use php+oracle to make an email table and insert Query tutorial, quickly point to see, from beginning to end carefully looked over, have not begun to operate, it felt a great harvest. Address here:Http://www.alixixi.com/program/a/2008050731615.shtml#replay.
Http://blog.163.com/[email protected]/blog/static/27712393201131815035122/(Blog campus)
Summary " HP provides 2 large classes of APIs (application interfaces) to operate 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.
In php3.0 and above, PHP contains almost all of the database processing functions currently in use, including Oracle, and in this article we have an example of how these functions can be used to manipulate Oracle databases.
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 ([email protected])
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.
Create A Table Using OCI
Below we will create an email personal information book. This time using the OCI8 API Directive
Related PHP Code:
PUTENV ("Oracle_sid=orasid");
$connection = Ocilogon ("username", "password");
if ($connection = = False) {
echo Ocierror ($connection). "
";
Exit
}
$query = "CREATE Table Email_info".
"(FullName varchar (255), email_address varchar (255))";
$cursor = Ociparse ($connection, $query);
if ($cursor = = False) {
echo Ocierror ($cursor). "
";
Exit
}
$result = Ociexecute ($cursor);
if ($result = = False) {
echo Ocierror ($cursor). "
";
Exit
}
Ocicommit ($connection);
Ocilogoff ($connection);
?>
We can see that the 2 code syntax is almost the same, the difference is only the function name is different; Second, in OCI8 we do not need to specifically run the instructions to open the cursor, in the callthe ociparse system automatically returns a cursor ID.
Use ORA to enter data into data table ' Email_info '
When the user browses the script, a form consisting of the name and email input field is displayed, and when the user clicks Submit, the script will save the name and email to the ' email_info ' data sheet.
Related PHP Code:
if ($submit = = "click") {
The Submit button was clicked!
Get the input for FullName and e-mail then store it in the database.
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 = "INSERT into email_info values (' $fullname ', ' $email ')";
$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);
}
else{
Echo '
Please enter your name
Please enter your email address
Span class= "Apple-converted-space" > 
';
}
? > 
Yes, this script must be saved as insert.php, because specifying insert.php as the form handler in the called page
Browsing effect:
Please enter your name Please enter an email address
|
Use OCI to enter data into data table ' Email_info '
Ditto, just use OCI to write
Related PHP Code:
if ($submit = = "click") {
The Submit button was clicked!
Get the input for FullName and e-mail then store it in the database.
PUTENV ("Oracle_sid=orasid");
$connection = Ocilogon ("username", "password");
if ($connection = = False) {
echo Ocierror ($connection). "
";
Exit
}
$query = "INSERT into email_info values (' $fullname ', ' $email ')";
$cursor = Ociparse ($connection, $query);
if ($cursor = = False) {
echo Ocierror ($cursor). "
";
Exit
}
$result = Ociexecute ($cursor);
if ($result = = False) {
echo Ocierror ($cursor). "
";
Exit
}
Ocicommit ($connection);
Ocilogoff ($connection);
}
else{
Echo '
Please enter your name
Please enter an email address
Yes, this script must be saved as insert.php, because specifying insert.php as the form handler in the called page
Browsing effect:
Please enter your name Please enter an email address
|
Use Ora to list data from all data tables ' Email_info '
Below, we will read out the contents of the database and display the data in the ' email_info ' table as an HTML table
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 = "SELECT * from Email_info";
$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
}
echo "";
echo "";
while (Ora_fetch_into ($cursor, & $values)) {
$name = $values [0];
$email = $values [1];
echo "";
}
echo "
Full Name |
Email Address |
$name |
$email |
";
Ora_close ($cursor);
Ora_logoff ($connection);
?>
The browsing effects of the program run are as follows:
|
name |
Email address |
Spring flower |
[email protected] |
Autumn month |
[email protected] |
... |
... |
|
|
Use OCI to list data in all data table ' Email_info '
Ditto, just use OCI to write
Related PHP Code:
PUTENV ("Oracle_sid=orasid");
$connection = Ocilogon ("username", "password");
if ($connection = = False) {
echo Ocierror ($connection). "
";
Exit
}
$query = "SELECT * from Email_info";
$cursor = Ociparse ($connection, $query);
if ($cursor = = False) {
echo Ocierror ($cursor). "
";
Exit
}
$result = Ociexecute ($cursor);
if ($result = = False) {
echo Ocierror ($cursor). "
";
Exit
}
echo "";
echo "";
while (Ocifetchinto ($cursor, $values)) {
$name = $values [0];
$email = $values [1];
echo "";
}
echo "
Full Name |
Email Address |
$name |
$email |
";
Ocilogoff ($connection);
?>
The browsing effects of the program run are as follows:
|
name |
Email address |
Spring flower |
[email protected] |
Autumn month |
[email protected] |
... |
... |
|