2014-04-17 40 views
2

我已經更新後,我的WordPress安裝到3.9,我不斷收到這些錯誤:錯誤在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,導致它切換到使用的mysqli PHP庫,使用PHP 5.5或更高。

當對於插件開發者,此裝置您絕對不應該再使用PHP的mysql _ *()函數 - 您可以使用等效的WPDB函數。「

+0

你看過這些錯誤消息?代碼沒有問題,WordPress無法連接到數據庫。在配置中檢查憑據。 –

+0

檢查了配置,並試圖用憑證輸入mysql。 沒有錯,那裏,似乎,因爲我成功登錄。 – oles

回答

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函數。

+0

確實!我用7小時前的這個解決方案更新了我的問題:) – oles

0
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; 
       } 
} ?> 
+0

感謝您的建議,但在我試了一下後,錯誤是一樣的。 – oles

+0

不使用mysql *函數它們已被棄用。使用WP核心函數或mysqli或pdo。第二你是不安全的數據。清理數據。 – Kavin

-1

它看起來像更新更改了mysql的用戶名和密碼。所以問題不在於代碼。

檢查wp-config.php文件,如果這些設置被更改和不正確的

+0

wp-config.php文件內沒有任何更改,它內部的憑證可用於訪問mysql。 – oles

2

更改爲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 
+1

很好的例子。 這就是我所做的 - 將所有舊的mysql_ *替換爲$ wpdb-> – oles