dqrmkdu25623 2015-07-18 21:08
浏览 31
已采纳

PDO默默地测试连接性

Is there a way I can either validate the connection parameters before making a connection using them, or alternatively turn off the warnings, so I can handle the errors myself? (by the way, ERRMODE_SILENT did not work)

I want my application to handle the errors, instead of displaying them in the output. This is a part of the constructor:

 try {
    $this->pdo = new PDO("mysql:host=$db_host;port=$db_port;dbname=$db_name", $db_user, $db_pass);
    $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);

 } catch (PDOException $e){
    $this->connEstablished = false;
    $this->error = $e->getMessage();
 }
  • 写回答

1条回答 默认 最新

  • dongqiao6730 2015-07-18 23:00
    关注

    Check your 'display_errors' setting in php.ini. See the PHP configuration file documentation.

    if 'display_errors' is 'On' then it will output any errors or warnings to the browser. Setting it to 'Off' will prevent this, and is almost always a good idea.

    This is controlled via php.ini, but can also be changed at runtime using the built-in function ini_set, which is useful if you do not have control over your environment (using a hosted server, etc.)

    You can check the current value with ini_get('display_errors') and turn it off with ini_set('display_errors', 'Off').

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口