我正在尝试使用单独的mysqli_connect.php文件连接到mysql数据库logindb 。这是我的代码:
<?php
// This creates a connection to the logindb database and to MySQL,
// It also sets the encoding.
// Set the access details as constants:
DEFINE('DB_USER', 'loger');
DEFINE('DB_PASSWORD', 'loger');
DEFINE('DB_HOST', 'localhost');
DEFINE('DB_NAME', 'logindb');
// Make the connection:
$dbcon = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Could not connect to MySQL: ' .
mysqli_connect_error());
// Set the encoding...
mysqli_set_charset($dbcon, 'utf8');
?>
我在Windows上使用XAAMP,但出现此错误:
无法连接到MySQL:未知数据库'logindb'
Windows防火墙在“入站规则”中阻止了Apache HTTP和mysql,我允许连接,但仍然是相同的错误。我真是糊涂了,怎么了?
编辑
我认为问题出在防火墙上,因为sql可能被阻止了!无论如何,我卸载了XAMPP并重新安装了它,然后再次进行了logindb的操作,并为用户添加了所有特权,现在它可以工作了。谢谢你!
根据您的错误:
似乎名称logindb
不存在的数据库。因此,请检查一次。
您@
在创建连接时也使用了它,可能是因为这样,您没有得到代码中正在发生的确切错误。因为@
用于跳过错误。
因此,除了上述内容之外,您的代码看起来还不错。也许听起来也很疯狂,但是请检查以下代码:-
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
// Make the connection:
$dbcon = mysqli_connect('localhost','loger','loger','logindb') or die('Could not connect to MySQL: ' .mysqli_connect_error());
// Set the encoding...
mysqli_set_charset($dbcon, 'utf8');
?>
或尝试一次
$dbcon = mysqli_connect('localhost','loger','','logindb') or die('Could not connect to MySQL: ' .mysqli_connect_error());
如果提供的话,还要检查密码是否正确。因为您在注释中的错误说明您使用的是错误的密码。
您可以尝试使用新密码创建新用户并运行代码。
所有这些工作完成后,如果什么都没有发生,请卸载并重新安装xampp
。谢谢
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句