mysql查看脚本错误位置,php-mysql脚本失败时如何获取详细的错误报告?

How do i get a detailed error description during a php-mysql script run?

I have the following statements where the script fails and displays the custom error message - the contents of the "or die".

I want to get the actual error from MySQL (instead of the custom error i have mentioned), which would give better idea about the scenario - whether its a database issue or server connectivity issue etc..

this is the code i have where i need to enhance the error reporting

$query = "SELECT * FROM table_name";

$result = mysqli_query($db_conn, $query)

or die('Connected to database, but querying failed');

thanks!

解决方案

Have a look at the manual page for mysqli_error. In the section "Procedural style" you'll find a complete example that shows how to set up the database connection and querying the database, both steps with error handling.

If you want detailed error information from your scripts you can put the lines

error_reporting( E_ALL );

ini_set('log_errors', true);

ini_set('error_log', '/tmp/php-errors.log');

at the start of your code. That way all errors coming from PHP will be written into the log file. Make sure that the path to the log file exists (/tmp is only an example) and is writable by the web server, otherwise the errors will be silently discarded.

As a side note: While the "or die()" pattern is good for small examples, you should not use it in production code.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值