Example #1
0
function DBexecute($query, $skip_error_messages = 0)
{
    global $DB;
    $result = false;
    $time_start = microtime(true);
    if (isset($DB['DB']) && !empty($DB['DB'])) {
        $DB['EXECUTE_COUNT']++;
        // WRONG FOR ORACLE!!
        //SDI('SQL xec: '.$query);
        switch ($DB['TYPE']) {
            case 'MYSQL':
                $result = mysql_query($query, $DB['DB']);
                if (!$result) {
                    error('Error in query [' . $query . '] [' . mysql_error() . ']');
                }
                break;
            case 'POSTGRESQL':
                if (!($result = pg_query($DB['DB'], $query))) {
                    error('Error in query [' . $query . '] [' . pg_last_error() . ']');
                }
                break;
            case 'ORACLE':
                $stid = OCIParse($DB['DB'], $query);
                if (!$stid) {
                    $e = @ocierror();
                    error('SQL error [' . $e['message'] . '] in [' . $e['sqltext'] . ']');
                }
                $result = @OCIExecute($stid, $DB['TRANSACTIONS'] ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS);
                if (!$result) {
                    $e = ocierror($stid);
                    error('SQL error [' . $e['message'] . '] in [' . $e['sqltext'] . ']');
                } else {
                    $result = $stid;
                }
                break;
            case 'SQLITE3':
                if (!$DB['TRANSACTIONS']) {
                    lock_db_access();
                }
                $result = sqlite3_exec($DB['DB'], $query);
                if (!$result) {
                    error('Error in query [' . $query . '] [' . sqlite3_error($DB['DB']) . ']');
                }
                if (!$DB['TRANSACTIONS']) {
                    unlock_db_access();
                }
                break;
        }
        if ($DB['TRANSACTIONS'] && !$result) {
            $DB['TRANSACTION_STATE'] &= $result;
            //			SDI($query);
            //			SDI($DB['TRANSACTION_STATE']);
        }
    }
    COpt::savesqlrequest(microtime(true) - $time_start, $query);
    return $result;
}
Example #2
0
function DBexecute($query, $skip_error_messages = 0)
{
    global $DB;
    $result = false;
    $time_start = microtime(true);
    if (isset($DB['DB']) && !empty($DB['DB'])) {
        $DB['EXECUTE_COUNT']++;
        //SDI('SQL xec: '.$query);
        switch ($DB['TYPE']) {
            case 'MYSQL':
                $result = mysql_query($query, $DB['DB']);
                if (!$result) {
                    error('Error in query [' . $query . '] [' . mysql_error() . ']');
                }
                break;
            case 'POSTGRESQL':
                $result = (bool) pg_query($DB['DB'], $query);
                if (!$result) {
                    error('Error in query [' . $query . '] [' . pg_last_error() . ']');
                }
                break;
            case 'ORACLE':
                $result = OCIParse($DB['DB'], $query);
                if (!$result) {
                    $e = @ocierror();
                    error('SQL error [' . $e['message'] . '] in [' . $e['sqltext'] . ']');
                } else {
                    if (!@OCIExecute($result, $DB['TRANSACTIONS'] ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS)) {
                        $e = ocierror($result);
                        error('SQL error [' . $e['message'] . '] in [' . $e['sqltext'] . ']');
                    } else {
                        /* It should be here. The function must return boolean */
                        $result = true;
                    }
                }
                break;
            case 'IBM_DB2':
                $options = array();
                if (!($result = db2_prepare($DB['DB'], $query))) {
                    $e = @db2_stmt_errormsg($result);
                    error('SQL error [' . $query . '] in [' . $e . ']');
                } else {
                    if (true !== @db2_execute($result)) {
                        $e = @db2_stmt_errormsg($result);
                        error('SQL error [' . $query . '] in [' . $e . ']');
                    } else {
                        /* It should be here. The function must return boolean */
                        $result = true;
                    }
                }
                break;
            case 'SQLITE3':
                if (!$DB['TRANSACTIONS']) {
                    lock_db_access();
                }
                $result = sqlite3_exec($DB['DB'], $query);
                if (!$result) {
                    error('Error in query [' . $query . '] [' . sqlite3_error($DB['DB']) . ']');
                }
                if (!$DB['TRANSACTIONS']) {
                    unlock_db_access();
                }
                break;
        }
        if ($DB['TRANSACTIONS'] && !$result) {
            $DB['TRANSACTION_STATE'] &= $result;
        }
    }
    COpt::savesqlrequest(microtime(true) - $time_start, $query);
    return (bool) $result;
}