Wordpress数据库致命错误

时间:2009-12-11 15:52:51

标签: php database wordpress

尝试针对我的WordPress数据库运行PHP脚本时收到此错误:

Fatal error: Cannot redeclare class wpdb

任何人都可以帮我解决这个问题吗?


修改

代码:

require_once(dirname(__FILE__) . '/../../wp-config.php'); 
require_once(dirname(__FILE__) . '/../../wp-includes/wp-db.php'); 
$wpdb->show_errors(); 
$dupes = $wpdb->get_results('select bad_rows.* from wp_posts as bad_rows inner join ( select post_title, MIN(id) as min_id from wp_posts group by post_title having count(*) > 1 ) as good_rows on good_rows.post_title = bad_rows.post_title and good_rows.min_id <> bad_rows.id; '); 

foreach ($dupes as $dupe) 
{ 
  echo $dupe->post_title ."\n"; 
}

$wpdb->query(' delete bad_rows.* from wp_posts as bad_rows inner join ( select post_title, MIN(id) as min_id from wp_posts group by post_title having count(*) > 1 ) as good_rows on good_rows.post_title = bad_rows.post_title and good_rows.min_id <> bad_rows.id; ');

3 个答案:

答案 0 :(得分:1)

我使用新安装的wordpress中的新functions.php文件替换了functions.php文件夹中已损坏的wp-includes文件。确保你从同一版本的wordpress中获得一个。不确定不同版本是否会获得相同的结果。

这解决了我Call to undefined function require_wp_db() /filename/filename/...wp-settings.php on line 71的问题,我可以登录。

我建议在安装侧边栏之前备份您的functions.php文件。这就是造成我问题的原因。

答案 1 :(得分:0)

您似乎将Wordpress引导程序包括两次。消除第二个电话或使用require_once()

您的PHP脚本如何?

答案 2 :(得分:0)

我只能通过自己的Wordpress安装,但是;

WP-config.php中;

[line 30] require_once(ABSPATH . 'wp-settings.php');

WP-settings.php文件;

[line 242] require_wp_db();

WP-包括/ functions.php的

[line 2534] function require_wp_db() {
                global $wpdb;
                if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
                    require_once( WP_CONTENT_DIR . '/db.php' );
                else
                    require_once( ABSPATH . WPINC . '/wp-db.php' );
            }

虽然您(和require_wp_db函数)使用require_once,但似乎您不必调用wp-includes / wp-db.php。尝试将其评论出来并查看问题是否消失。如果没有,请按照下面的步骤进入wp-config.php,注释掉包含的内容。希望你能够隔离引起问题的那条线......