无法连接到MySQL db,PHP

时间:2017-11-13 12:24:01

标签: php mysql phpmyadmin

您好我正在尝试使用mircloud主机服务连接MySQL数据库但它没有连接。我尝试使用phpMyAdmin在本地连接,但仍然给我这个错误。这是我的连接代码。

<!-- connot connect to database -->
<?php
define (DB_USER, "root");
define (DB_PASSWORD, "gOJTkc7QSL");
define (DB_DATABASE, "rbkLastTask");
define (DB_HOST, "https://node42861-env-2276018.mircloud.host");
?>

<?php  
$server = DB_HOST;
$user = DB_USER;
$pw = DB_PASSWORD;
$db = DB_DATABASE;
// $con = mysqli_connect($server,$user,$pw,$db);
$con=mysqli_connect($server,$user,$pw,$db);
Echo mysqli_connect_error();
if($con)
{
    echo "success";
}
else
{
    echo "failed";
}
?>

1 个答案:

答案 0 :(得分:0)

试试这段代码

以这种方式编写代码

<?php 
define ("DB_USER", "root"); //use "" for DB_USER
define ("DB_PASSWORD", "");//use "" for DB_PASSWORD
define("DB_DATABASE", "test");//use "" for DB_DATABASE
define ("DB_HOST", "localhost");  //use "" for DB_HOST

$server = DB_HOST; $user = DB_USER; $pw = DB_PASSWORD; $db = DB_DATABASE; // $con = mysqli_connect($server,$user,$pw,$db);
$con=mysqli_connect($server,$user,$pw,$db) or die (mysqli_connect_error()); //remove ; and echo and add or for die()
if($con) { echo "success"; } else { echo "failed"; } ?>