Cuprins
- Contents
- Introduction to PHP 2
- PHP ORACLE EXTENSIONS 2
- Oracle Extension 3
- OCI8 Extension 3
- PDO Extension 4
- CONNECTING TO ORACLE USING OCI8 5
- Oracle Connection Types 5
- Standard Connections 5
- Multiple Unique Connections 5
- Persistent Connections 5
- Oracle Database Name Connection Identifiers 7
- Easy Connect String 7
- Database Connect Descriptor String 8
- Database Connect Name 8
- Closing Oracle Connections 9
- Close Statement Resources Before Closing Connections 9
- Conclusion 11
- BIBLIOGRAPHY 11
Extras din referat
Introduction to PHP
PHP has one of those recursive names, PHP Hypertext Preprocessor. It was originally designed around web programming, but has since evolved to be a full-fledged scripting language like Perl. Far and away the strength of PHP is in its community, and how it has evolved. Rather than being designed at the outset to be everyone's ideal language and framework, PHP has evolved a huge base of developers, and libraries of functions that people needed in the real world.
PHP is a hugely popular, interpreted scripting language commonly used for web applications. PHP is open source and free, and has a BSD-style license, making it corporation-friendly. PHP is perfect for rapidly developing applications both big and small, and is great for creating Web 2.0 applications. It powers over twenty million web sites on the Internet and has a huge user community behind it. It runs on many platforms.
The language is dynamically typed and easy to use. PHP comes with many extensions offering all kinds of functionality such as database access. PHP 5 introduced strong object orientated capabilities.
PHP ORACLE EXTENSIONS
PHP has several extensions that let applications use Oracle. There are also database abstraction libraries written in PHP which are popular. Although this book concentrates on the OCI8 extension for PHP, it is worth knowing the alternatives.
Database access in each extension and abstraction library is fundamentally similar. The differences are in their support for advanced features and the programming methodology promoted. If you want to make full use of Oracle's features and want high performance then use OCI8, which is PHP’s main Oracle extension. If you want database independence, consider using the PHP Data Object (PDO) extension or the ADOdb abstraction library.
The PHP world can move at a fast pace, so examine your requirements and the latest information available before starting a project.
The PHP Oracle extensions are written in C and linked into the PHP binary. The extensions are:
- Oracle
- OCI8
- PDO
You can also use the ODBC extension.
Oracle Extension
The extension called “Oracle” was included in PHP 3, 4 and 5.0. It had limited functionality, is no longer in PHP, and is not maintained. The extension accessed the database using Oracle’s obsolete “OCI7” C language API. New development using this extension is not recommended.
OCI8 Extension
OCI8 is the recommended extension to use. It is included in PHP 3, 4, and 5. It is also in PHP 6, which is in the early stage of development. It is open source and maintained by the PHP community. Oracle is a member of the community looking after OCI8.
There have been major and minor changes to the OCI8 extension in various versions of PHP. It is recommended to upgrade the default OCI8 code in PHP 4 – PHP 5.2 to the latest version of the extension. An example script that finds city names from the locations table using OCI8:
Script 1: intro.php
<?php
$c = oci_connect('hr', 'hrpwd', 'localhost/XE');
$s = oci_parse($c, 'select city from locations');
oci_execute($s);
while ($res = oci_fetch_array($s, OCI_ASSOC)) {
echo $res['CITY'] . "<br>";
}
?>
When invoked in a web browser, it connects as the demonstration user hr of the Oracle Database XE database running on the local machine. The query is executed and a web page of results is displayed in the browser:
Figure 1: PHP Output in a web browser.
In PHP 5, some extension function names were standardized. PHP 4 functions like OCILogin() became oci_connect(), OCIParse() became oci_parse() and so on. The old names still exist as aliases, so PHP 4 scripts do not need to be changed. A table showing old and new names appears in Appendix C. The name “OCI8” is also the name for Oracle’s Call Interface API used by C programs such as the PHP OCI8 extension. All unqualified references to OCI8 in this book refer to the PHP extension.
PDO Extension
PHP Data Objects (PDO) is a data abstraction extension that provides PHP functions for accessing databases using a common core of database independent methods. Each database has its own driver, which may also support vendor specific functionality. PDO_OCI provides the Oracle functionality for PDO. The PDO extension and PDO_OCI driver are open source and included in PHP 5.1 onwards.
Preview document
Conținut arhivă zip
- Oracle and PHP.doc