Welcome Guest, Not a member yet? Register   Sign In
Difference between db->insert and db->insert_string
#1

[eluser]rahendz[/eluser]
i'm just curious, first sorry for my bad english

1. is there any difference between insert function with insert_string function?

2. could i retrieve insert_id when running insert_string like insert function?

3. could i do something like this

Code:
return $this->db->insert($table,$data)->insert_id();

thanks before.
#2

[eluser]CroNiX[/eluser]
insert() performs the query and insert_string() only returns the SQL as a string, but doesn't perform the actual query.

For # 3, you wouldn't want to do that. insert() returns TRUE/FALSE depending on if there was an error executing the insert.

This would be safer:
Code:
if ($this->db->insert($table, $data))
{
  //no error on insert, return insert id
  return $this->db->insert_id();
}
return FALSE; //insert was unsuccessful so there is no insert_id to send

#3

[eluser]rahendz[/eluser]
Aha, big thanks for fast reply and explanation :thumbsup:




Theme © iAndrew 2016 - Forum software by © MyBB