mysqli连接给出警告:mysqli_connect(),而我正在使用try catch块

时间:2013-11-30 09:15:51

标签: php

我的代码是这样的..

$host = "localhost";
$user = "root";
$password = "";
$database = "db1";
$port = "3306";
$socket = "";
try {
    mysqli_connect($host, $user, $password, $database, $port, $socket); 
    echo 'Connected to database';
} catch (mysqli_sql_exception $e) {
    echo $e->errorMessage();
}

1 个答案:

答案 0 :(得分:1)

你必须使用

$link = mysqli_connect($host, $user, $password, $database) or die("Error " . mysqli_error($link));