2013-04-02 52 views
0

我的虚拟专用服务器出现问题。 VPS主办2个WordPress的网站。 自上周以来,服务器突然开始有时会产生错误,并且两个网站在前端显示下面的错误。重新启动Apache网络服务器后,它可以再次运行1或2天,但这次似乎正在减少。为foreach提供的无效参数 - 建立数据库连接时出错

这是在前端产生的错误是:

"Warning: Invalid argument supplied for foreach() in /var/www/html/domainname/wp-includes/locale.php on line 117 Warning: Invalid argument supplied for foreach() in /var/www/html/domainname/wp-includes/locale.php on line 159 Error establishing a database connection"

Locale.php的内容:(什么也没有改变这个)

function init() { 
    // The Weekdays 
    $this->weekday[0] = /* translators: weekday */ __('Sunday'); 
    $this->weekday[1] = /* translators: weekday */ __('Monday'); 
    $this->weekday[2] = /* translators: weekday */ __('Tuesday'); 
    $this->weekday[3] = /* translators: weekday */ __('Wednesday'); 
    $this->weekday[4] = /* translators: weekday */ __('Thursday'); 
    $this->weekday[5] = /* translators: weekday */ __('Friday'); 
    $this->weekday[6] = /* translators: weekday */ __('Saturday'); 

    // The first letter of each day. The _%day%_initial suffix is a hack to make 
    // sure the day initials are unique. 
    $this->weekday_initial[__('Sunday')] = /* translators: one-letter abbreviation of the weekday */ __('S_Sunday_initial'); 
    $this->weekday_initial[__('Monday')] = /* translators: one-letter abbreviation of the weekday */ __('M_Monday_initial'); 
    $this->weekday_initial[__('Tuesday')] = /* translators: one-letter abbreviation of the weekday */ __('T_Tuesday_initial'); 
    $this->weekday_initial[__('Wednesday')] = /* translators: one-letter abbreviation of the weekday */ __('W_Wednesday_initial'); 
    $this->weekday_initial[__('Thursday')] = /* translators: one-letter abbreviation of the weekday */ __('T_Thursday_initial'); 
    $this->weekday_initial[__('Friday')] = /* translators: one-letter abbreviation of the weekday */ __('F_Friday_initial'); 
    $this->weekday_initial[__('Saturday')] = /* translators: one-letter abbreviation of the weekday */ __('S_Saturday_initial'); 

    foreach ($this->weekday_initial as $weekday_ => $weekday_initial_) { 
     $this->weekday_initial[$weekday_] = preg_replace('/_.+_initial$/', '', $weekday_initial_); 
    } 

    // Abbreviations for each day. 
    $this->weekday_abbrev[__('Sunday')] = /* translators: three-letter abbreviation of the weekday */ __('Sun'); 
    $this->weekday_abbrev[__('Monday')] = /* translators: three-letter abbreviation of the weekday */ __('Mon'); 
    $this->weekday_abbrev[__('Tuesday')] = /* translators: three-letter abbreviation of the weekday */ __('Tue'); 
    $this->weekday_abbrev[__('Wednesday')] = /* translators: three-letter abbreviation of the weekday */ __('Wed'); 
    $this->weekday_abbrev[__('Thursday')] = /* translators: three-letter abbreviation of the weekday */ __('Thu'); 
    $this->weekday_abbrev[__('Friday')] = /* translators: three-letter abbreviation of the weekday */ __('Fri'); 
    $this->weekday_abbrev[__('Saturday')] = /* translators: three-letter abbreviation of the weekday */ __('Sat'); 

    // The Months 
    $this->month['01'] = /* translators: month name */ __('January'); 
    $this->month['02'] = /* translators: month name */ __('February'); 
    $this->month['03'] = /* translators: month name */ __('March'); 
    $this->month['04'] = /* translators: month name */ __('April'); 
    $this->month['05'] = /* translators: month name */ __('May'); 
    $this->month['06'] = /* translators: month name */ __('June'); 
    $this->month['07'] = /* translators: month name */ __('July'); 
    $this->month['08'] = /* translators: month name */ __('August'); 
    $this->month['09'] = /* translators: month name */ __('September'); 
    $this->month['10'] = /* translators: month name */ __('October'); 
    $this->month['11'] = /* translators: month name */ __('November'); 
    $this->month['12'] = /* translators: month name */ __('December'); 

    // Abbreviations for each month. Uses the same hack as above to get around the 
    // 'May' duplication. 
    $this->month_abbrev[__('January')] = /* translators: three-letter abbreviation of the month */ __('Jan_January_abbreviation'); 
    $this->month_abbrev[__('February')] = /* translators: three-letter abbreviation of the month */ __('Feb_February_abbreviation'); 
    $this->month_abbrev[__('March')] = /* translators: three-letter abbreviation of the month */ __('Mar_March_abbreviation'); 
    $this->month_abbrev[__('April')] = /* translators: three-letter abbreviation of the month */ __('Apr_April_abbreviation'); 
    $this->month_abbrev[__('May')] = /* translators: three-letter abbreviation of the month */ __('May_May_abbreviation'); 
    $this->month_abbrev[__('June')] = /* translators: three-letter abbreviation of the month */ __('Jun_June_abbreviation'); 
    $this->month_abbrev[__('July')] = /* translators: three-letter abbreviation of the month */ __('Jul_July_abbreviation'); 
    $this->month_abbrev[__('August')] = /* translators: three-letter abbreviation of the month */ __('Aug_August_abbreviation'); 
    $this->month_abbrev[__('September')] = /* translators: three-letter abbreviation of the month */ __('Sep_September_abbreviation'); 
    $this->month_abbrev[__('October')] = /* translators: three-letter abbreviation of the month */ __('Oct_October_abbreviation'); 
    $this->month_abbrev[__('November')] = /* translators: three-letter abbreviation of the month */ __('Nov_November_abbreviation'); 
    $this->month_abbrev[__('December')] = /* translators: three-letter abbreviation of the month */ __('Dec_December_abbreviation'); 

    foreach ($this->month_abbrev as $month_ => $month_abbrev_) { 
     $this->month_abbrev[$month_] = preg_replace('/_.+_abbreviation$/', '', $month_abbrev_); 
    } 

我没有改变在php或mysql配置中的任何东西,我不知道为什么它开始表现得像这样。

临时解决方案是重新启动httpd服务,然后一切都将罚款约1天,但似乎这次减少到有时一个半小时。

起初我以为这个问题是由Mysql造成的。不过,我配置了一个测试工具来测试mysql。在VPS遇到问题时,通过Mysql testtool登录到数据库时没有问题。

说实话,我不是PHP大师,希望有人能让我走上正轨。我一直在解决和浏览论坛几个小时,但现在我不知道如何解决它。

如果您需要更多信息,请询问。 非常感谢提前。

最好的问候, 罗伯特

回答

2

尝试检查他们的是他们是数组或之前没有像

if(is_array($this->weekday_initial)) 
    foreach ($this->weekday_initial as $weekday_ => $weekday_initial_) 
+0

循环“警告:提供的foreach()无效参数”是指我们是否已通过非数组或它可能是数据库问题... – Gautam3164

+0

嗨,谢谢。 我该如何检查? – user2235385

+0

首先检查选择功能,从中获取数据....然后查询和参数传递....还回显您的SQL查询并在您的数据库中运行它,如果结果不来,那么有问题您的查询 – Gautam3164