如何使用php连接MySQL db(xampp)?

时间:2017-05-29 08:07:21

标签: php mysql xampp

我正在尝试连接到phpstorm中的mysql数据库,但我没有成功。 我将非常感谢你的帮助。

<?php
$servername = "http://localhost:8012";
$username = "root";
$password = "";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}else{
die("Connected successfully");
}

错误是:502 Bad Gateway

2 个答案:

答案 0 :(得分:1)

您可以像这样连接数据库:

ClaimsPrincipal

答案 1 :(得分:0)

&#13;
&#13;
<?php
$servername = "localhost:8012";
$username = "root";
$password = "";
$database = "dbname";

// Create connection
$conn = mysqli_connect($servername, $username, $password,$database) or die(mysqli_error($conn);

echo "Connection Successful";
&#13;
&#13;
&#13;