簡體   English   中英

使用MS sql數據庫時記錄錯誤

[英]Log error when working with MS sql database

我寫了一個php頁面/腳本,它連接到ms sql db並執行一些插入/更新。 可能會發生錯誤,因此我想將它們記錄到文件中。

日志記錄功能的當前版本為:

function logMsSqlError($fileStream){
        fwrite($fileStream, "Error: ".mssql_get_last_message()."\n");
        fwrite($fileStream,urldecode(http_build_query( error_get_last()))."\n" );
}

它的用法如下:

 $res = mssql_query($q, $dbhandle);
        if(!$res) {
                logMsSqlError($fh);
                fclose($fh);
                die("query failed");
        }

問題在於,發生錯誤時,在網頁中我會看到很多有用的信息:

"Warning: mssql_query(): message: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Test1". 

The conflict occurred in database "testDb", table "dbo.testTable", column 'TestColumn'. (severity 16) in /var/www/html/sms/utilities.php on line 31 

Warning: mssql_query(): General SQL Server error: Check messages from the SQL Server (severity 16) in /var/www/html/sms/utilities.php on line 31 

Warning: mssql_query(): Query failed in /var/www/html/sms/utilities.php on line 31"

而在日志文件中,我無法捕獲所有這些詳細信息。 現在我得到:

Error: The statement has been terminated.
type=2&message=mssql_query(): Query failed&file=/var/www/html/sms/utilities.php&line=31

如何獲取日志文件中瀏覽器錯誤的詳細信息? (網頁中的詳細信息來自何處?)

您有兩種選擇:您可以在php.ini中打開log_errors或使用set_error_handler函數將您自己的日志記錄系統與PHP錯誤處理程序集成在一起。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM