繁体   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