当我运行下面的代码时
$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: 1064You 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/