In the previous pages, i told that i have got Zend Core For Oracle installed on my computer. For this reason, there is Zend Core Administration link under Start/All Programs/Zend Core For Oracle. Lets click this link. In the Welcome page, we will be asked password. This is the password that we entered when we were installing Zend Core For Oracle. In the openning page there is a Configuration tab. Under Configuration tab, there is a page about Extensions. We will set our php by turning on or turning off this lambs in this page. We will change the red lambs to green lambs of oci8 and pdo_oci extensions for Oracle. After these changes we can connect to our Oracle db.
Create new file and name it example2.php. Let’s connect to db from our example2.php file.
- First step is to define which db we are going to connect for this reason we will write the username, password and service_name to get permission.
<?php
$conn = oci_connect(’hr’, ‘oracle’, ‘//localhost/XE’);
?>
First parameter is the username, second one is password and the third one is our computername/service_name.
∞In Oracle database, databases are created under users. In above example, hr is the user that has our datas, functions, triggers.
If we want to connect to remote database server, we need IP address of this computer, like:
<?php
$conn = oci_connect(’hr’, ‘oracle’, ‘//192.168.1.60/XE’);
?> - After first step, if we succeed to connect, we can write any sql statement we like. To do this:
<?php
$conn = oci_connect(’hr’, ‘oracle’, ‘//localhost/XE’);
$stid = oci_parse($conn, ’select * from locations’);
?> - To execute the statement that we wrote above:
<?php
$conn = oci_connect(’hr’, ‘oracle’, ‘//localhost/XE’);
$stid = oci_parse($conn, ’select * from locations’);
oci_execute($stid,OCI_DEFAULT);
?> - Write codes that are above and save our example.php file. If we run our example.php, we will see the data from locations table.
<?php
$conn = oci_connect(’hr’, ‘oracle’, ‘//localhost/XE’);
$stid = oci_parse($conn, ’select * from locations’);
oci_execute($stid,OCI_DEFAULT);
print ‘<table border=”1″>’;
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS)) {
print ‘<tr>’;
foreach ($row as $item) {
print ‘<td>’.($item?$item:’ ‘).’</td>’;
}
print ‘</tr>’;
}
print ‘</table>’;
?>
