PHP Classes
elePHPant
Icontem

PHP PDO OCI: Access Oracle databases using a PDO class wrapper

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files Documentation   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2015-07-27 (5 days ago) RSS 2.0 feedNot enough user ratingsTotal: 354 This week: 30All time: 6,379 This week: 22Up
Version License PHP version Categories  
pdo-oci 1.0.6GNU General Publi...5PHP 5, Databases
Description Author  

This class can access Oracle databases using a PDO class wrapper.

It provides a replacement for the PDO class that wraps around PHP Oracle OCI functions to access Oracle databases.

The class gets the available PDO drivers and insert the oci driver if it is not supported in the current PHP PDO installation.

Recommendations  

What is the best PHP oracle oci8 class?
DB class with CRUD, Function calls, Stored Procedures

Innovation Award  
PHP Programming Innovation award winner
March 2014
Winner


Prize: One downloadable e-book of choice by O'Reilly
PDO is a PHP extension that was introduced to provide a certain level of abstraction to access different types of databases.

However, sometimes it is necessary to access a database from components that use PDO, but the driver extension to access the specific type of database is not available in the current PHP environment.

This class implements a pure PHP replacement for PDO Oracle database driver, so it works with the OCI extension when the PDO OCI driver is not available.

Manuel Lemos
Picture of Eustaquio Rangel de Oliveira Jr.
Name: Eustaquio Rangel de ... is available for providing paid consulting. Contact Eustaquio Rangel de ... .
Classes: 5 packages by
Country: Brazil Brazil
Age: 44
All time rank: 29824 in Brazil Brazil
Week rank: 17 Up1 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

Details provided by the author  

PDOCI

Wrapping on PHP OCI functions to simulate a PDO object, using just pure PHP and the oci_* functions.

Let's face it. Installing PHP, PDO, Oracle drivers and PDO OCI is not a pleasant task. Is more pleasant to insert bamboo sticks under your fingernails than make all the voodoo needed to accomplish that task. And there are two big problems with that:

  1. If you install pdo_oci with pecl you'll get a version from 2005 (http://pecl.php.net/package/PDO_OCI). Even Christian Bale is now far from the things from 2005, and wow, he had a cool suit and a very nice car. And all came in black.
  2. If you follow the official docs, you'll need to compile PHP and still get an experimental extension (http://www.php.net/manual/ref.pdo-oci.php). Come on. We can't (yeah, we know how to do it!) compile PHP on every server we need and just for an experimental feature?

That's why I made PDOOCI.

What is needed

Just install the Oracle drivers (I like the instant client versions) and the oci8 package (with pecl, this one seems to be updated often). Then require the pdooci.php file and change some existing code like

$pdo = new PDO("oci:dbname=mydatabase;charset=utf8", "user", "password");

to

require_once "pdooci.php";

$pdo = new PDOOCI\PDO("mydatabase", "user", "password");

Yeah, the rest should work exactly the same as if you were using a PDO object. :-)

Testing

There is a test suite (using PHPUnit) on the test directory. If you want to test (you must test your code!), create a table called people with two columns:

  1. name as varchar2(50)
  2. email as varchar2(30)

And some environment variables:

  1. PDOOCI_user with the database user name
  2. PDOOCI_pwd with the database password
  3. PDOOCI_str with the database connection string

And then go to the test dir and run PHPUnit like:

phpunit --colors .
  Files folder image Files  
File Role Description
Files folder imagesrc (3 files)
Files folder imagetest (2 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. Auxiliary data
Accessible without login Plain text file README.md Doc. Auxiliary data

  Files folder image Files  /  src  
File Role Description
  Plain text file PDO.php Class Class source
  Plain text file Statement.php Class Class source
  Plain text file StatementIterator.php Class Class source

  Files folder image Files  /  test  
File Role Description
  Accessible without login Plain text file connectionTest.php Test Unit test script
  Accessible without login Plain text file statementTest.php Test Unit test script

 Version Control Unique User Downloads Download Rankings  
 100%Total:354All time:6,379
 This week:30This week:22Up