<?php

// oracle.inc.php - PHProjekt Version 5.0
// copyright  ©  2000-2005 Albrecht Guenther  ag@phprojekt.com
// www.phprojekt.com
// Author: Albrecht Guenther, $Author: paolo $
// $Id: oracle.inc.php,v 1.4 2005/06/06 16:06:19 paolo Exp $

// check whether lib.inc.php has been included
if (!defined("lib_included")) die("Please use index.php!");

// Connect

$dbIDnull = "null";

$link = OCILogon($db_user, $db_pass, $db_name);
$datestmt = OCIParse($link, "alter session set NLS_DATE_FORMAT='YYYY-MM-DD HH:MI:SS'");
OCIExecute($datestmt);
if (!$link) die("<b>Database connection failed!</b><br>Call admin, please.");

// execute sql query
function db_query($query) {
    global $link;

    if (eregi('insert|update|delete|create',$query)) {
        if ( (eregi('insert', $query)) && (stristr($query, '(null,')) ) {
            $tok = explode (" ", $query);
            $seq_name = $tok[2];
            $seq_name = '('.$seq_name."_id_seq.nextval";
            $query = str_replace ('(null,', $seq_name, $query);
        }
        $stmt = OCIParse($link, $query);
        OCIExecute($stmt);
        $commit_stmt = OCIParse($link, 'commit');
        OCIExecute($commit_stmt);
    }
    else {
        $stmt = OCIParse($link, $query);
        OCIExecute($stmt);
    }
    return $stmt;
}

// fetch row statement
function db_fetch_row ($result) {
    OCIFetchInto($result, $row, OCI_RETURN_NULLS+OCI_RETURN_LOBS);
    return $row;
}

// Error-Messages
function db_die() {
    echo OCIError($stmt);
    die("</body></html>");
}

// error code
function get_sql_errno($resource) {
    $error = OCIError();
    if ($error !== false) {
        return $error['code'];
    }
    return '';
}

?>
