php - 消息 : Object of class stdClass could not be converted to string in codeigniter

标签 php mysql database codeigniter

当我运行下面的代码时

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

我收到这个错误

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

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

最佳答案

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

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

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

关于php - 消息 : Object of class stdClass could not be converted to string in codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20251878/

相关文章:

php - 您如何根据本地 Active Directory 验证云服务?

mysql - PMA 数据库...在 phpMyAdmin 升级中不正常

mysql - Laravel 4 播种口音

database - 我是否需要创建一个我想用 H2 预填充的表?

php - 数据库错误代码 1146 - 本地与在线

mysql - 不访问数据库的 Perl DBI

php使用循环重新启动脚本执行的时间限制

php - Internet Explorer 中的 Ajax 和 JSON 响应错误(适用于所有其他浏览器)

php - 将 SQL 结果移植到 memcached 中

php - 优化查询SQL