我写了一个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错误处理程序集成在一起。
关于php - 使用MS sql数据库时记录错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11794904/