【发布时间】:2014-06-01 15:15:16
【问题描述】:
将我的 Wordpress 安装更新到 3.9 后,我不断收到以下错误:
Warning: mysql_query(): Access denied for user 'www-data'@'localhost' (using password: NO) in /home/sites/wordpress/site/wp-content/plugins/crm/main.php on line 20
Warning: mysql_query(): A link to the server could not be established in /home/sites/wordpress/site/wp-content/plugins/crm/main.php on line 20
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in /home/sites/wordpress/site/wp-content/plugins/crm/main.php on line 21
我不知道出了什么问题。这是 3.9 之前的代码:
<?php
session_start();
/**
* Plugin Name: CRM
* Description:
* Version:
* Author:
*
*/
add_action( 'admin_menu', 'menu' );
function menu() {
add_menu_page( 'CRM', 'CRM', 3,'form', 'form' );
}
function form() {
global $wpdb,$current_user,$user_ID;
echo "<h3>CRM</h3>";
$count = mysql_query("SELECT COUNT(id) FROM user_form_data");
$nume2 = mysql_fetch_row($count);
$nume = $nume2[0];
我已经剪掉了其余部分,因为它似乎与错误无关:)
解决方案:
找到了。
错误出现在 3.9 升级中。
http://make.wordpress.org/core/2014/04/07/mysql-in-wordpress-3-9/
“在 WordPress 3.9 中,我们为 WPDB 添加了一个额外的层,使其在使用 PHP 5.5 或更高版本时切换到使用 mysqli PHP 库。
对于插件开发人员,这意味着您绝对不应该再使用 PHP 的 mysql_*() 函数——您可以使用等效的 WPDB 函数。”
【问题讨论】:
-
你读过那些错误信息了吗?代码没有问题,WordPress无法连接到数据库。检查配置中的凭据。
-
检查了配置,并尝试使用凭据进入 mysql。似乎没有什么问题,因为我成功登录了。
标签: mysql wordpress plugins upgrade wordpress-3.9