【问题标题】:Message: Object of class stdClass could not be converted to string in codeigniter消息:类 stdClass 的对象无法在 codeigniter 中转换为字符串
【发布时间】:2013-12-13 15:36:26
【问题描述】:

当我运行下面的代码时

  $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);

我收到此错误

遇到 PHP 错误 严重性:4096
消息:stdClass 类的对象无法转换为字符串 文件名:mysql/mysql_driver.php 行号:552 错误号:1064

您的 SQL 语法有错误;查看与您的 MySQL 服务器版本相对应的手册,了解在 ' ' 附近使用的正确语法

我已经尝试更改输入值,但仍然出现相同的错误。任何帮助,将不胜感激。我该如何解决这个问题?

【问题讨论】:

    标签: php mysql database codeigniter


    【解决方案1】:

    您正在尝试将object 转换为string。请确保$category_id$img_name 不是object

    看看这里,这可能对你有帮助。 Object of class stdClass could not be converted to string

    您可以 sse:$this->db->last_query(); 返回上次运行的查询(查询字符串,而不是结果)。从那里您可以轻松查看查询字符串,这也可以帮助您找出实际错误。

    【讨论】:

    • 感谢您的回复。看来我在定义 $category_id 变量时犯了一个错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 1970-01-01
    • 2019-07-27
    • 2011-04-06
    相关资源
    最近更新 更多