[英]Error establishing a database connection wordpress inspite of correct credentials in config file
I'm getting Error establishing a database connection error whenever I load my HomePage ie index.php. 每当加载我的主页(即index.php)时,我都会收到建立数据库连接错误的错误消息。
I have created a new test.php file with the same credentials as wp-config.php file to check the credentials and it works fine. 我创建了一个新的test.php文件,该文件具有与wp-config.php文件相同的凭据,以检查凭据,并且工作正常。 I get Connected successfully message.
我收到成功连接消息。
But when I run index.php file I get 但是当我运行index.php文件时,我得到了
Error establishing a database connection.
建立数据库连接时出错。
What could cause this error? 是什么导致此错误?
Test.php file Test.php文件
<?php
$link = mysqli_connect('localhost', 'username', 'password', 'dbname');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
Remove all above connection code from test.php file. 从test.php文件中删除所有上述连接代码。
just use global $wpdb;
只需使用全局$ wpdb; in beginning of file & it will give you connectivity from the config file.
在文件开头,它将为您提供来自配置文件的连接。 its wordpress's default functionality.
它的wordpress的默认功能。
The problem was with one of my plugins. 问题出在我的一个插件上。 I had to remove the plugin to make it work properly.
我必须删除插件才能使其正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.