Oracle Connect
Oracle Connect
• Oracle products
• OCI8 extension
• Connection management
• Improving performance
• XML
• Oracle resources
Oracle Database Express Edition
• Free to download,
develop, deploy, and
distribute
• Small footprint
• 32-bit Linux and
Windows
• Free OTN community
forum for support
• Uses native install on
Windows and Linux
• Application Express GUI
Oracle SQL Developer
• Abstraction Libraries
• Database independence
• Lowest common denominator
• PEAR DB
• PEAR MDB2
• ADOdb
• ODBC
• PDO
• OCI8
OCI8 Extension
<?php
$conn = oci_connect('hr', 'hr', '//localhost/XE');
$sql = oci_parse($conn, 'select city from locations');
oci_execute($sql);
while ($row = oci_fetch_assoc($sql))
echo $row['CITY'] . "<br>";
?>
OCI8 Connections
• Standard Connection
• oci_connect()
• Multiple Unique Connections
• oci_new_connect()
• Persistent Connection
• oci_pconnect()
• oci8.max_persistent
• oci8.persistent_timeout
• oci8.ping_interval
• Close connections
• oci_close()
• oci8.old_oci_close_semantics
Database Connections
Idle Idle
Idle Idle
Idle Idle
Idle Idle
Idle Idle
Idle Idle
Idle Idle
Idle Idle
Idle Persistent
Idle Persistent
Connection
Monitor
Idle
$s = oci_parse($c,
"select last_name from employees
where employee_id = :eidbv");
$myeid = 101;
oci_bind_by_name($s, ":EIDBV", $myeid);
oci_execute($s);
oci_fetch_all($s, $res);
echo "Last name is: ". $res['LAST_NAME'][0] ."<br>\n";
$myeid = 102;
oci_execute($s); // No need to re-parse
oci_fetch_all($s, $res);
echo "Last name is: ". $res['LAST_NAME'][0] ."<br>\n";
PL/SQL
<?php
$c = oci_connect('hr', 'hr', '//localhost/XE');
$s = oci_parse($c, "call myproc('mydata', 123)");
oci_execute($s);
?>
Database Transactions
• oci_execute() auto-commits
• Commits cause
• Round-trips to the database
• Database I/O
This is slow
This is better
May be fastest
• XML DB
• Stored as
• Relational data
• Linear as LOBs
• XML Schema structure
• SELECT XMLELEMENT
• PL/SQL Package DBMS_XMLGEN
• XQuery
SELECT XMLELEMENT
$query =
'SELECT XMLELEMENT("Employees",
XMLELEMENT("Name", first_name),
XMLELEMENT("Id", employee_id)) as result
FROM employees WHERE department_id = 10';
$s = oci_parse($c, $query);
oci_execute($s);
while ($row = oci_fetch_row($s))
foreach ($row as $item)
echo htmlentities($item)." ";
<Employees><Name>Joanne</Name><Id>210</Id></Employees>
<Employees><Name>Jennifer</Name><Id>200</Id></Employees>
DBMS_XMLGEN Package
<?xml version="1.0"?>
<ROWSET>
<ROW>
<FIRST_NAME>Joanne</FIRST_NAME>
<EMPLOYEE_ID>210</EMPLOYEE_ID>
</ROW>
...
</ROWSET>
Oracle Technology Network
PHP Developer Centre
• Technical Articles
• Install guides
• Underground PHP
and Oracle Manual
• Discussion forum
• JDeveloper 10g
PHP extension
• Blogs
otn.oracle.com/php
Oracle Resources