dsbqfrr098575666 2013-11-27 11:55
浏览 62
已采纳

消息:类stdClass的对象无法在codeigniter中转换为字符串

When I run the code below

  $data = array(
                'name' => $this->input->post('name'),
                'recipe' => $this->input->post('recipe'),
                'category_id' => $category_id,
                'recipe_elements' => $this->input->post('recipe_elements'),
                'country' => $this->input->post('country'),
                'video' => $this->input->post('video'),
                'img' => $img_name,
                'vote' => $this->input->post('oy')
            );

            $this->db->insert('recipes',$data);

I get this error

A PHP Error was encountered Severity: 4096
Message: Object of class stdClass could not be converted to string Filename: mysql/mysql_driver.php Line Number: 552 Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' '

I already tried to change the input values but still getting the same error. Any help would be appreciated. How can I fix this?

  • 写回答

1条回答 默认 最新

  • dongre1907 2013-11-27 12:10
    关注

    You're trying to convert an object to a string.Please make sure $category_id and $img_name is not an object.

    Take a look here this may help you. Object of class stdClass could not be converted to string

    You can sse:$this->db->last_query(); which Returns the last query that was run (the query string, not the result). From where you can see easily your query string which also help you findout actual error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部