My SQL in this PHP script cannot connect to my phpmyadmin-database on my XAMMP server:
<?php
//Shows every Error
error_reporting('E_All');
//used Host
define('MYSQL_HOST ', 'localhost');
//Name of SQL user
define('MYSQL_USER', 'root');
//Password of User
define('MYSQL_PASSWORD', '');
//Name of database
define('MYSQL_DATABASE', 'phpmodul');
?>
<?php
$db_link = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);
if ($db_link)
{
echo 'Connection OK:', print_r($db_link);
}
else
{
die('No connection: ' . mysql_error());
}
?>
When I execute it, it just prints No connection: php_network_getadressinfo failed: The Host is unkown.
I am using PHP version 5.2.0 and XAMPP version 5.6.28
Edit1 Changed mysqli_* to mysql_*
I have found the solution:
<?php
$con = mysqli_connect("localhost","root","","phpmodul");
if (mysqli_connect_error())
{
echo "Connection not possible: " . mysqli_connect_error();
}
else
{
echo "Connection succsessfully established.";
}
?>
Hello Dear I get you problem,
Please Remove Space From
define('MYSQL_HOST', 'localhost');
OR Replace line
define('MYSQL_HOST ', 'localhost');
TO
define('MYSQL_HOST', 'localhost');