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:
-
If you install
pdo_oci
withpecl
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. -
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
.
First install the Oracle drivers (I like the instant client versions) and the
oci8
package (with pecl
, this one seems to be updated often).
$ composer require taq/pdooci
{
"require": {
"taq/pdooci": "^1.0"
}
}
<?php
require_once 'vendor/autoload.php';
$pdo = new PDOOCI\PDO("mydatabase", "user", "password");
Why are you not using composer? Download the src
folder from the repo and rename it to PDOOCI
, then require the PDOOCI/PDO.php
file.
require_once "PDOOCI/PDO.php";
$pdo = new PDOOCI\PDO("mydatabase", "user", "password");
Yeah, the rest should work exactly the same as if you were using a PDO object. :-)
There is a test suite (using PHPUnit
with a version bigger than 6.x) on the test
directory. If you want to
test (you must test your code!), create a table called people
with two
columns:
name
asvarchar2(50)
email
asvarchar2(30)
And some environment variables:
PDOOCI_user
with the database user namePDOOCI_pwd
with the database passwordPDOOCI_str
with the database connection string
And then go to the test
dir and run PHPUnit
like:
phpunit --colors .