Ignore:
Timestamp:
06/12/13 11:43:20 (12 years ago)
Author:
tbretz
Message:
Implemented some debug out to a log-file when the sql query fails.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/www/shift/calendar.php

    r15155 r16813  
    22
    33require_once("config.php");
     4
     5function log_sql_error($query, $error)
     6{
     7    if (!file_exists("log/"))
     8        mkdir("log/", 0777, true);
     9
     10    $file = fopen("log/mysql.log", "a");
     11    fwrite($file, date("Y-m-d H:i:s")."\n".$query."\n".$error."\n\n");
     12    fclose($file);
     13
     14    return header('HTTP/1.0 500 '.$error);
     15}
    416
    517function login()
     
    7486
    7587if (!mysql_connect($dbhost, $dbuser, $dbpass))
    76     return header('HTTP/1.0 500 '.mysql_error());
     88    return log_sql_error("connect: ".$dbhost."[".$dbuser."]", mysql_error());
    7789
    7890if (!mysql_select_db($dbname))
    79     return header('HTTP/1.0 500 '.mysql_error());
     91    return log_sql_error("select_db: ".$dbname, mysql_error());
    8092
    8193if (isset($_GET['comment']))
     
    8799    $result = mysql_query($query);
    88100    if (!$result)
    89         return header('HTTP/1.0 500 '.mysql_error());
     101        return log_sql_error($query, mysql_error());
    90102
    91103    if (isset($_GET['d']))
     
    126138        $c = $_GET['c'];
    127139
    128         if (!mysql_query("DELETE FROM Comments WHERE y=".$y." AND m=".$m." AND d=".$d))
    129             return header('HTTP/1.0 500 '.mysql_error());
     140        $query = "DELETE FROM Comments WHERE y=".$y." AND m=".$m." AND d=".$d;
     141        if (!mysql_query($query))
     142            return log_sql_error($query, mysql_error());
    130143
    131         if (strlen($c)>0)
    132             if (!mysql_query("INSERT Comments SET y=".$y.", m=".$m.", d=".$d.", c='".$c."'"))
    133                 return header('HTTP/1.0 500 '.mysql_error());
     144        if (strlen($c)<=0)
     145            return;
     146
     147        $query = "INSERT Comments SET y=".$y.", m=".$m.", d=".$d.", c='".$c."'";
     148        if (!mysql_query($query))
     149            return log_sql_error($query, mysql_error());
     150
    134151        return;
    135152    }
     
    137154    $u = isset($_GET['u']) ? $_GET['u'] : $_SERVER['PHP_AUTH_USER'];
    138155
    139     if (!mysql_query("DELETE FROM Data WHERE y=".$y." AND m=".$m." AND d=".$d." AND u='".$u."'"))
    140         return header('HTTP/1.0 500 '.mysql_error());
     156    $query = "DELETE FROM Data WHERE y=".$y." AND m=".$m." AND d=".$d." AND u='".$u."'";
     157    if (!mysql_query($query))
     158        return log_sql_error($query, mysql_error());
    141159
    142160    if (mysql_affected_rows()==0)
    143161    {
    144         $x = $_GET['x'];
    145         if (!mysql_query("INSERT Data SET y=".$y.", m=".$m.", d=".$d.", x=".$x.", u='".$u."'"))
    146             return header('HTTP/1.0 500 '.mysql_error());
     162        $x = $_GET['x'];
     163
     164        $query = "INSERT Data SET y=".$y.", m=".$m.", d=".$d.", x=".$x.", u='".$u."'";
     165        if (!mysql_query($query))
     166            return log_sql_error($query, mysql_error());
    147167    }
    148168}
     
    154174$result = mysql_query($query);
    155175if (!$result)
    156     return header('HTTP/1.0 500 '.mysql_error());
     176    if (!mysql_query($query))
     177        return log_sql_error($query, mysql_error());
    157178
    158179while ($row = mysql_fetch_array($result, MYSQL_NUM))
Note: See TracChangeset for help on using the changeset viewer.