Let’s run a PHP example app from Windows to an Autonomous Transaction Processing database
instance.
In this example, XAMPP is installed on windows to run PHP and the PHP extension OCI8.
Oracle Instant Client is installed to connect the app to the database instance.
An Example php app is downloaded from Github and modified to use the PHP extension OCI8
to connect to the ATP database instance.
XAMPP is a common way students install PHP on a web server.
Before using XAMPP, make sure it satisfies your business needs.
You should have already
provisioned an ATP database instance called demo.
Downloaded the ATP demo database instance wallet and extracted it to a temporary folder.
And have created a user called demo_user.
If you need help with any of these prerequisites, go to the ATP
help center,
click videos, select and watch the Provision Autonomous
Transaction Processing video.
To find documentation of the steps shown in this video,
go to installing Xampp on Windows for PHP and Oracle Database
posted on blogs.oracle.com/opal.
Go to apachefriends.org to download XAMPP.
Select XAMPP for Windows.
This example uses version 7.3.2.
The download starts for xampp-windows x64.
Run the downloaded executable and follow the installer windows instructions
to install Apache and PHP to an XAMPP folder.
In this example, XAMPP is installed on the D drive.
Go to the folder where XAMPP is installed and click on xampp-control.exe to start the
XAMPP control panel.
Click on the control panel Apache start button to start Apache.
In the php folder where xampp is installed, open php.ini in notepad.
Find extension=oci8_12c and uncomment the statement.
The PHP extension DLL named php_oci8_12c.dll is located on the D drive, in the XAMPP/ PHP/ext
folder.
In the php.ini file, find extension_dir=
Make sure it is set to the directory containing the PHP extension dll.
Save the file.
XAMPP is now installed and includes: Apache Web Server, PHP and PHP Extension OCI8.
Next, install Oracle Instant Client.
Go to Oracle Technical Resources, search for Oracle Instant Client Downloads and select it.
Because the installed xampp version was for windows x64,
select the Instant Client for Windows x64.
And accept the license agreement.
Download the zip for instantclient basic for windows x64 version 12.2.0.1.0
Extract the files to the D drive.
A subdirectory instantclient_12_2 is created.
Go back to the Instant Client Downloads page, and click the link to download Microsoft Visual
Studio 2013 Redstributable.
From the advanced system properties, go to the Environment variables and edit the value
of the PATH system variable to include the instant client location and the xampp location,
then save.
Now that the instantclient directory exists,
copy the wallet files downloaded and extracted earlier
from the temp folder to a network\admin folder under the location instant client is installed.
If the network slash admin folders do not exists, create them.
To get the updated PATH, stop the Apache server from the XAMPP console,
then start it again.
Any open command windows will need to be reopened to get the new path.
From a browser, Visit http://localhost/dashboard/phpinfo.php and scroll to the OCI8 category.
The extension has loaded successfully.
Oracle Instant Client installation is complete.
Now, download the example app from GitHub and modify it to connect to the ATP Database.
To obtain the example.php app used in this example, go to github.com/oracle.
Search for oracle-db-examples and select it.
Click on the exadata dash express folder.
Select example.php.
Save as Example.php in the XAMPP htdocs folder.
Open saved example.php in Notepad.
This code connects to the ATP database, creates a table, inserts some data and performs a
simple query on that data.
Change username to demo_user.
Edit Password so it’s the actual demo_user password, defined when the user for the demo
instance was created.
Finally, modify the connect underscore string to demo underscore low, which is defined in
the tnsnames.ora file downloaded earlier in the wallet.
Then Save the file.
Now that the example app has been downloaded and modified to connect to the ATP database
instance,
It’s time to run the app against the ATP database.
Load the example app in to a browser using http://localhost/Example.php
The example app connects to the ATP database, creates and populates a table, then returns
the table data for display.
Congratulations.
You’ve successfully set-up a PHP environment to communicate with an ATP database.
Learn more at cloud.oracle.com