#native_company# #native_desc#

Database Abstraction Layer for oracle.

By yavor
on August 31, 2000

Version: 1.0

Type: Function

Category: Databases

License: GNU General Public License

Description: Oracle database abstraction layer so you don’t have to hard-code oci?() all over your code. This is a port of tims database.php file. It’s not completly functional as some functions couldn’t be ported to oracle, I think I managed to get the ovaral usability of it. Bug come it plenty so just mail me about it 😉

//  Port of the database abstraction layer found on www.phpbuilder.com
//  All old code is commented out
//  Must have $sys_dbhost,$sys_dbuser,$sys_dbpasswd declared in some include file
//  By: yavor
//  Date: 31/08/00
//  E-mail:[email protected]

function db_connect() {
//        global $sys_dbhost,$sys_dbuser,$sys_dbpasswd;
//        $conn = mysql_connect($sys_dbhost,$sys_dbuser,$sys_dbpasswd);
//        if (!$conn) {
//                echo mysql_error();
//        }
//        return $conn;
        global $sys_dbhost,$sys_dbuser,$sys_dbpasswd,$_conn;
        $_conn = ociplogon($sys_dbuser,$sys_dbpasswd,$sys_dbhost);
        if (!$_conn) {
                echo "Error connecting to the database<br>n.Username:$sys_dbuser<br>Password:$sys_dbpasswd<br>nDBServer:$sys_dbhost";
        return $_conn;


function db_query($qstring) {
//        global $sys_dbname; NOTE:In oracle you don't have to specify the database
//        return @mysql($sys_dbname,$qstring);
//        oracle functions require a $conn so in the db_connect function I set
//        the $conn to be a global variable.
//        here i set the statment handler as a global also, required for
//        db_numrows and db_numfields functions
          global $_conn,$_stmt;
          $cur = ociparse($_conn,$qstring);
          $_stmt = $cur;
          return $cur;

function db_numrows($qhandle) {
        // return only if qhandle exists, otherwise 0
        //if ($qhandle) {
        //        return @mysql_numrows($qhandle);
        //} else {
        //        return 0;
        // Havent figured out how to do this yet. there isn't a compatible
        // function in oci to do this
        echo "This function is not supported in this port";
        return 0;

function db_result($qhandle,$row,$field) {
        //return @mysql_result($qhandle,$row,$field);
        echo "This function is not supported in this port";
        return 0;

function db_numfields($lhandle=0) {
//        return @mysql_numfields($lhandle);
          global $_stmt;
          return OCINumCols($_stmt);

function db_fieldname($lhandle=0,$fnumber) {
//        return @mysql_fieldname($lhandle,$fnumber);
          global $_stmt;
          return OCIColumnName($_stmt,$fnumber);

function db_affected_rows($qhandle) {
//        return @mysql_affected_rows();
          return OCIRowCount($qhandle);

function db_fetch_array($qhandle,$assoc=1,$get_lobs=0) {
//        return @ mysql_fetch_array($qhandle);
//        If you want a numbered array then set assoc to 0
//        If you have a binary field CLOB/BLOB set the third param to 1
//        i know these are ugly hacks but I couldn't figure out
//        another way to do it
          $param = OCI_RETURN_NULLS;
          echo $param;
           $param = $param + OCI_ASSOC;
           $param = $param + OCI_RETURN_LOBS;

          echo $param;

          return $data;

function db_insertid($qhandle) {
//        return @mysql_insert_id($qhandle);
//        this is also not supported by oracle
//        for insert id oracle uses sequenses, there maybe a hack availble here
//        yet by selecting the currvar from the sequence but this requires the sequence name
//        to be known. For now wait.
          echo "This function is not supported in this port";

function db_error() {
        return "nn<P><B>Oracle error:".OCIError()."</B><P>nn";