<?php

// ms_sql.inc.php - PHProjekt Version 5.0
// copyright  ©  2000-2005 Albrecht Guenther  ag@phprojekt.com
// www.phprojekt.com
// Author: Albrecht Guenther, $Author: paolo $
// $Id: ms_sql.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 = "msnull";
$link = mssql_connect($db_host, $db_user, $db_pass);
$conn = mssql_select_db($db_name);
if (!$link or (isset($conn) and !$conn)) die("<b>Database connection failed!</b><br>Call admin, please.");

// execute sql query
function db_query($query) {
    $sPattern  = 'msnull[ ]*,';
    $sNewQuery = eregi_replace($sPattern, '', $query);
    if ($sNewQuery != $query) {
        $sPattern  = '\([ ]*ID[ ]*,';
        $sNewQuery = eregi_replace($sPattern, '(', $sNewQuery);
        $sPattern  = '\,[ ]*ID[ ]*,';
        $sNewQuery = eregi_replace($sPattern, ',', $sNewQuery);
    }
    $sPattern  = '\\\\\'';
    $sSubst    = '\'\'';
    $sNewQuery = eregi_replace($sPattern, $sSubst, $sNewQuery);
    $sPattern  = '\\\\"';
    $sSubst    = '"';
    $sNewQuery = eregi_replace($sPattern, $sSubst, $sNewQuery);
    return mssql_query($sNewQuery);
}

// fetch row statement
function db_fetch_row($result) {
    return mssql_fetch_row($result);
}

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

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

?>
