【问题标题】:did not switch on or die command in php没有在php中打开或死亡命令
【发布时间】:2013-03-21 08:28:06
【问题描述】:

我已经编写了这些代码。但他们没有很好地工作。它有一些像这样的错误:

Warning: mysqli_connect() [function.mysqli-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\wamp\www...

有时会显示T_EXIT 错误。 我的问题在于“或死”命令。假设它无法连接到数据库。然后它应该打开“或死亡”并终止程序。但它没有这样做。我该如何解决?

$dbc = mysqli_connect('localhost', 'user', 'pass', 'table')
 or die('Error connecting to MySQL server.');

【问题讨论】:

    标签: die


    【解决方案1】:

    My problem is in "or die" command. Suppose it cannot connect to database. Then it should switch on "or die" & terminates the the program.

    答案直接来自PHP Manual

    $link = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');
    
    if (!$link) {
        die('Connect Error (' . mysqli_connect_errno() . ') '.mysqli_connect_error());
    }
    

    【讨论】:

      猜你喜欢
      • 2018-12-11
      • 1970-01-01
      • 2010-10-10
      • 1970-01-01
      • 2014-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      相关资源
      最近更新 更多