简体   繁体   English

CodeIgniter inser / update_batch(可能)

[英]CodeIgniter inser/update_batch (probably)


I have a little problem with my CodeIgniter application. 我的CodeIgniter应用程序有一个小问题。

The code works on apache installed on my laptop, it works on my online server as well, but not on the client's host... ;) 该代码可在我的笔记本电脑上安装的apache上运行,也可在我的在线服务器上运行,但不能在客户端主机上运行;;)

Error info: 错误信息:

Severity: Warning
Message: array_keys() expects parameter 1 to be array, boolean given
Filename: database/DB_active_rec.php
Line Number: 1113

A PHP Error was encountered
Severity: Warning
Message: sort() expects parameter 1 to be array, null given
Filename: database/DB_active_rec.php
Line Number: 1114

A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: database/DB_active_rec.php
Line Number: 1144

A Database Error Occurred
You must use the "set" method to update an entry.

It seems the problem is about insert_batch & update_batch methods. 看来问题出在关于insert_batch和update_batch方法。

Any ideas? 有任何想法吗?

The code is very simple, it works on 2 of 3 servers I've run it. 代码非常简单,可以在我运行过的3台服务器中的2台上运行。 Two functions: 两个功能:

public function insert_tabs($fb_user_id, $fanpages) {
        $tabs = array();
        foreach($fanpages as $fanpage) {
            $entry['ta_user_fb_id'] = $fb_user_id;
            $entry['ta_fanpage_id'] = $fanpage['fa_fanpage_id'];
            $entry['ta_text'] = "Put your content here.";

            $tabs[] = $entry;
        }

        return $this->db->insert_batch('tabs', $tabs);
    }

And: 和:

function set_random_links($entries) {
    $insert = array();
    foreach($entries as $fanpage) {
        $fanpage_id = $fanpage['fa_fanpage_id'];
        $links = $this->get_random_links();

        foreach($links as $link) {
            $entry['lf_fb_fanpage_id'] = $fanpage_id;
            $entry['lf_link_id'] = $link->li_id;

            $insert[] = $entry;
        }
    }

    return $this->db->insert_batch('linksonfanpages', $insert);
}

In theory everything is fine. 从理论上讲,一切都很好。

cross check php version, MySQL version and check whether all files are upload properly. 交叉检查php版本,MySQL版本,并检查是否所有文件都正确上传。

Most of the time this error occurs due to the version mismatch. 在大多数情况下,此错误是由于版本不匹配而发生的。

First this error means your $fanpages is not an array. 首先,此错误表示您的$ fanpages不是数组。

A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: database/DB_active_rec.php
Line Number: 1144


public function insert_tabs($fb_user_id, $fanpages) {
        $tabs = array();
        if(is_array($fanpages)) {

              foreach($fanpages as $fanpage) {
                  $entry['ta_user_fb_id'] = $fb_user_id;
                  $entry['ta_fanpage_id'] = $fanpage['fa_fanpage_id'];
                  $entry['ta_text'] = "Put your content here.";

                  $tabs[] = $entry;
              }
         }
         if(count($tabs)) return $this->db->insert_batch('tabs', $tabs);
         return -1;
}

Also, can we see the source of $fanpages? 另外,我们可以看到$ fanpages的来源吗? Because it seems the whole issue if coming from that. 因为这似乎是整个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM