Domanda

After I've updated my Wordpress install to 3.9, I keep getting these errors:

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

I can't quite figure out what's wrong. Here's the code that worked pre-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];

I've snipped the rest, as it does not seem relevant for the error :)

SOLUTION:

Found it.

The error was in the 3.9 upgrade.

http://make.wordpress.org/core/2014/04/07/mysql-in-wordpress-3-9/

"In WordPress 3.9, we added an extra layer to WPDB, causing it to switch to using the mysqli PHP library, when using PHP 5.5 or higher.

For plugin developers, this means that you absolutely shouldn’t be using PHP’s mysql_*() functions any more – you can use the equivalent WPDB functions instead."

È stato utile?

Soluzione

You should read this post http://make.wordpress.org/core/2014/04/07/mysql-in-wordpress-3-9/

In WordPress 3.9, we added an extra layer to WPDB, causing it to switch to using the mysqli PHP library, when using PHP 5.5 or higher.

For plugin developers, this means that you absolutely shouldn’t be using PHP’s mysql_*() functions any more – you can use the equivalent WPDB functions instead.

Altri suggerimenti

Change this to wp_results

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

to

$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
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;   
                }
} ?>

It looks like that the update changed the mysql username and password. So the problem isn't the code.

Check the wp-config.php file if these settings are changed and incorrect

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top