mysqli_connect("","username" ,"password","databasename");//Server name cannot be NULL
使用loaclhost服務器名(在Loacl)
<?php
$con = mysqli_connect("localhost","username" ,"password","databasename");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
或者可以使用庫MySQLi程序
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$con = mysqli_connect($servername, $username, $password);
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
編輯01
$servername = "localhost";
$username = "root";
$password = "";
嘗試在'mysqli_connect'中指定'hostname'。 – 73ey
這是因爲主機參數既不爲空也未設置。它幾乎是空的。所以mysql現在不能連接到「」。 – pbalazek