<?php

// sqlite.inc.php - PHProjekt Version 5.0
// copyright 2000-2005 Albrecht Guenther ag@phprojekt.com
// www.phprojekt.com
// Author: Albrecht Günther, Johann-Peter Hartmann $Author: paolo $
// $Id: sqlite.inc.php,v 1.6 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";

// name of the database file
define('SQLITEDBFILENAME', dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.$db_name.".db");

if (!$sqlitedblink = sqlite_open(SQLITEDBFILENAME, 0666, $sqliteerror)) {
    die("<b>Database connection failed: $sqliteerror!</b><br>Call admin, please.");
}

// execute sql query
function db_query($query) {
    global $sqlitedblink;
    $query = ereg_replace("\\\'", "''", $query);
    $query = ereg_replace('\\\"', '""', $query);
    // remote secondary keys from create table statement
    $query = preg_replace('#(,\s*(KEY|INDEX)\s*\([^)]+\))#msiU', '', $query);
    $res = sqlite_query($sqlitedblink, $query);
    if ( !$res ) {
        echo "Error executing sqlite_query($sqlitedblink, $query)<br>";
        echo sqlite_error_string(sqlite_last_error($sqlitedblink)).'<br>';
    }
    return $res;
}

// fetch row statement
function db_fetch_row($result) {
    return sqlite_fetch_array($result, SQLITE_NUM);
}

// Error-Messages
function db_die() {
    global $dblink;
    echo '<pre>';
    echo sqlite_error_string(sqlite_last_error($dblink));
    die("</body></html>");
}

// error code
function get_sql_errno($resource) {
    return sqlite_error_string();
}

?>
