Reputation: 7
I have this:
<?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();
}
?>
But it doesn't say anything or do anything. Does someone know how to fix this, or has another idea to connect to MySQL?
Upvotes: 0
Views: 101
Reputation: 773
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
//Replace above details with your real server deatils
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
Upvotes: 0
Reputation: 4824
can you do this and see if there is an error
<?php
$con = mysqli_connect("HostName","UserName","password","DBName") or die("Some error occurred during connection " . mysqli_error($con));
?>
according to https://www.w3schools.com/php/func_mysqli_connect_errno.asp
Example Return an error code from the last connection error, if any:
<?php
$con=mysqli_connect("localhost","wrong_user","my_password","my_db");
// Check connection
if (!$con)
{
die("Connection error: " . mysqli_connect_errno());
}
?>
Upvotes: 1