此PHP脚本中的我的SQL无法连接到我的XAMMP服务器上的phpmyadmin-database:
<?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());
}
?>
当我执行它时,它只打印No connection: php_network_getadressinfo failed: The Host is unkown.
我使用的是PHP 5.2.0版和XAMPP 5.6.28版
Edit1 将mysqli_ *更改为mysql _ *
答案 0 :(得分:0)
我找到了解决方案:
<?php
$con = mysqli_connect("localhost","root","","phpmodul");
if (mysqli_connect_error())
{
echo "Connection not possible: " . mysqli_connect_error();
}
else
{
echo "Connection succsessfully established.";
}
?>
答案 1 :(得分:0)
你好亲爱的,我找到你的问题,
请删除空间
define('MYSQL_HOST', 'localhost');
或替换行
define('MYSQL_HOST ', 'localhost');
要
define('MYSQL_HOST', 'localhost');