首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为foreach提供的参数无效-建立数据库连接时出错

为foreach提供的参数无效-建立数据库连接时出错
EN

Stack Overflow用户
提问于 2013-04-02 17:38:20
回答 1查看 273关注 0票数 0

我的虚拟专用服务器出现问题。VPS托管了2个wordpress网站。从上周开始,服务器有时突然开始产生错误,两个网站都在前端显示了下面的错误。在重新启动Apache but服务器后,1到2天内可以再次正常运行,但这段时间似乎正在减少。

前端产生的错误为:

"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的内容:(没有对此进行任何更改)

代码语言:javascript
复制
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测试工具登录到数据库没有问题。

老实说,我不是php大师,希望有人能把我带到正确的轨道上。我自己解决问题和浏览论坛已经有几个小时了,但我现在不知道如何解决这个问题。

如果您需要更多信息,请联系我们。在此之前,非常感谢您。

致以最好的问候,罗伯特

EN

回答 1

Stack Overflow用户

发布于 2013-04-02 17:39:39

尝试在for循环之前检查它们是否为数组,例如

代码语言:javascript
复制
 if(is_array($this->weekday_initial))
     foreach ($this->weekday_initial as $weekday_ => $weekday_initial_)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15760782

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档