数据库无法连接

时间:2017-06-11 21:05:49

标签: php mysql database

我有这个:

<?php
$username = 'md409951db381343'
$password = '*******';
$host = 'localhost';
$database = 'md409951db381343'

if (mysqli_connect($host, $username, $password, $database)){
    if (mysqli_connect_errno()){
        echo 'Sorry, er ging iets mis: '.mysqli_connect_errno();
        exit();
    }
} else {
    echo 'Sorry, ik kon helaas geen verbinding maken met de database server';
    exit();
}
?>

但它没有说什么或做什么。有人知道如何解决这个问题,或者有其他想法连接MySQL吗?

2 个答案:

答案 0 :(得分:1)

你可以这样做,看看是否有错误

<?php
$con = mysqli_connect("HostName","UserName","password","DBName") or die("Some error occurred during connection " . mysqli_error($con));
?>

根据https://www.w3schools.com/php/func_mysqli_connect_errno.asp

实施例 返回上次连接错误的错误代码,如果有的话:

<?php
$con=mysqli_connect("localhost","wrong_user","my_password","my_db");
// Check connection
if (!$con)
  {
  die("Connection error: " . mysqli_connect_errno());
  }
?>

答案 1 :(得分:0)

__('Buy').' '.__($colour).' '.__('car');