【问题标题】:Error in Wordpress plugin after upgrade to 3.9升级到 3.9 后 Wordpress 插件出错
【发布时间】: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


【解决方案1】:
Try this hope this help



    <?php 
        /**
         * Plugin Name: CRM
         * Description:  any desc
         * Author: ABS
         *
         */

        add_action( 'admin_menu', 'user_data_menu' );

        function user_data_menu() {
                add_menu_page( 'CRM', 'CRM', 3,'user_data_form', 'user_data_form' );
        }

        function user_data_form() {
                @session_start();
                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];
                if ( $limit < $nume && empty($_POST['searching']) && empty($_POST['filter_flag']) && empty($_POST['rowsselect']) ) {
                        $start = $_GET['start'];
                        $eu = ($start - 0);
                        $limit = 20;
                        $this4 = $eu + $limit;
                        $back = $eu - $limit;
                        $next = $eu + $limit;   
                }
} ?>

【讨论】:

  • 谢谢你的建议,但我试了一下,还是一样的错误。
  • 不要使用 mysql* 函数,它们已被弃用。使用 WP 核心功能或 mysqli 或 pdo。 2你不是安全的数据。清理数据。
【解决方案2】:

看来更新更改了mysql用户名和密码。所以问题不在于代码。

检查 wp-config.php 文件是否更改了这些设置并且不正确

【讨论】:

  • wp-config.php 文件内部没有任何改变,并且其中的凭据可以访问 mysql。
【解决方案3】:

你应该阅读这篇文章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 函数。

【讨论】:

  • 确实!我在 7 小时前用这个解决方案更新了我的问题 :)
【解决方案4】:

将此更改为 wp_results

$count = mysql_query("SELECT COUNT(id) FROM user_form_data");
$nume2 = mysql_fetch_row($count);

$count =  $wpdb->get_results("SELECT COUNT(id) FROM user_form_data",ARRAY_A);
$nume2 = $wpdb->num_rows; ====== it will return same as mysql_fetch_row

【讨论】:

  • 很好的例子。这就是我所做的 - 将所有旧的 mysql_* 替换为 $wpdb->
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-24
  • 2021-12-01
  • 1970-01-01
  • 2020-04-19
相关资源
最近更新 更多