-4

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";
}
?>
Don't Panic
  • 13,965
  • 5
  • 32
  • 51

1 Answers1

0

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"; } ?>
Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39
  • sorry but it give me this error : Access denied for user 'root'@'localhost' (using password: NO) – Ammar Al-Ahmad Nov 13 '17 at 12:44
  • you can try with your user name password – Bhargav Chudasama Nov 13 '17 at 12:45
  • This looks right to me, but adding an explanation would greatly increase the quality of your answer. What did you do, and why do you think it will help? *Explain* your answer, so future visitors of all skill levels can learn from it. [Code-only answers are considered low quality on SO](https://meta.stackoverflow.com/questions/300837/what-comment-should-i-add-to-code-only-answers) – Don't Panic Nov 13 '17 at 13:08