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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20251878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:00:17  来源:igfitidea点击:

Message: Object of class stdClass could not be converted to string in codeigniter

phpmysqldatabasecodeigniter

提问by nihirus

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 ' '

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

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

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

我已经尝试更改输入值,但仍然遇到相同的错误。任何帮助,将不胜感激。我怎样才能解决这个问题?

回答by Suvash sarker

You're trying to convert an objectto a string.Please make sure $category_idand $img_nameis not an object.

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

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

看看这里这可能对你有帮助。类 stdClass 的对象无法转换为字符串

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.

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