在php中没有打开或死命令

时间:2013-03-21 08:28:06

标签: die

我写过这些代码。但它们效果不佳。它有这样的错误:

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.');

1 个答案:

答案 0 :(得分:0)

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());
}