Welcome Guest, Not a member yet? Register   Sign In
Checking if SQL statement failed with active record
#1

[eluser]ToretoTech[/eluser]
Hey all!

I was just wondering if there was a way to know if an SQL statement failed or completed successfully using active record.

Example:

If I have an insert statement like
Quote:$this->db->insert($this->_table,$data);

What can I do to see if this completed successfully or not?

Thank you!
TT
#2

[eluser]mi6crazyheart[/eluser]
Of course, if any thing wrong will happen in u'r SQL query then CI/PHP will definitely show u the error. Even if , u feel any thing going wrong but u r not getting any error then u can directly check u'r DB table via u'r console/terminal/PHPMyAdmin for proper updating in the respective fields.
#3

[eluser]Mark Croxton[/eluser]
Code:
if ($this->db->insert($this->_table,$data))
{
   // success
}
else
{
   // fail
}
#4

[eluser]Clooner[/eluser]
You can also get the number of affected rows using
Code:
$this->db->affected_rows()
For more information please read the user guide, search in the forum and wiki. I'm sure you are not the first having to see if a query was successful or not and the answer is out there ;-)
#5

[eluser]ToretoTech[/eluser]
Thanks for the replies.

I actually refer to the documentation all the time.
The active record pages say nothing about success or failure.
But, yes you're right. I assume I'm not first to ask this question.




Theme © iAndrew 2016 - Forum software by © MyBB