Hello I am trying to connect MySQL database using mircloud host service but it does not connect. I tried to connect locally using phpMyAdmin but still give me this error. This is my connect code.
<!-- 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";
}
?>
try this code
write this way your code
<?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"; } ?>