【问题标题】:CI ERROR :Cannot use object of type CI_DB_mysqli_result as arrayCI 错误:不能使用 CI_DB_mysqli_result 类型的对象作为数组
【发布时间】:2016-12-28 16:23:26
【问题描述】:

我正在尝试向 mysql 插入多个数组,但出现这样的错误

消息:不能使用 CI_DB_mysqli_result 类型的对象作为数组

文件名:operator_pt/Wsmahasiswa.php

行号:357

这是我的控制器代码

$database1 = $username1.'_'.$token.'_'.$temphmspt;
        $table1 = 'mahasiswa';
        $data1 = $this->db->query("select nm_pd from $database1");
        foreach($data1->result() as $key1){
        $filter1 = "nm_pd like '$key1->nm_pd'";
        $order1 = "nm_pd asc";
        $limit1 = 10;
        $offset1 = 0;
        $tampan1 = $proxy->GetRecordset($token, $table1, $filter1, $order1, $limit1, $offset1);
        $tampan1=$data1;
        $insert = $this->db->replace($database, $data1["result"]); //line 357

    }

这里是数组示例

Array
(
    [error_code] => 0
    [error_desc] => 
    [result] => Array
        (
            [0] => Array
                (
                    [id_pd] => cb5ab906-a9b5-49f2-95e9-0d30ce005bd9
                    [nm_pd] => BABABA

                )

            [1] => Array
                (
                    [id_pd] => f29128c2-27a0-4300-a4f5-842573e9e804
                    [nm_pd] => BIBIBI

                )

        )

)
Array
(
    [error_code] => 0
    [error_desc] => 
    [result] => Array
        (
            [0] => Array
                (
                    [id_pd] => 70500b08-a285-4e97-af0c-e8e43d2e5be6
                    [nm_pd] => BUBUBU

                )

【问题讨论】:

  • 你没有像这样使用result() $data1["result"]
  • 你的意思是这样吗? $insert = $this->db->replace($database, $data1->result());
  • 你想用$data1["result"]做什么?

标签: php mysql arrays codeigniter


【解决方案1】:

使用 $data1->result_array() 而不是 $data1->result() 它会给你结果数组

【讨论】:

    猜你喜欢
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多