Query Error Codeigniter
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more codeigniter mysql error handling about Stack Overflow the company Business Learn more about hiring developers or posting ads
Codeigniter Active Record Error Handling
with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack codeigniter query error handling Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up CodeIgniter - how to catch DB errors? up vote 36 down vote call to undefined method ci_db_mysql_driver::_error_message() favorite 6 Is there a way to make CI throw an exception when it encounters a DB error instead of displaying a message like: A Database Error Occurred Error Number: 1054 Unknown column 'foo' in 'where clause' SELECT * FROM (`FooBar`) WHERE `foo` = '1' NOTE: I only want this to happen in one controller. In the other controllers, I'm happy for it to display the DB error messages.
Codeigniter Db Query
php codeigniter share|improve this question edited Oct 20 '11 at 23:29 asked Oct 20 '11 at 23:22 StackOverflowNewbie 10k68188338 add a comment| 7 Answers 7 active oldest votes up vote 34 down vote accepted Try these CI functions $this->db->_error_message(); (mysql_error equivalent) $this->db->_error_number(); (mysql_errno equivalent) share|improve this answer edited Oct 21 '11 at 4:22 answered Oct 21 '11 at 4:17 Oskenso Kashi 51147 3 And when the queries are dinamically created, $this->db->last_query() useful too. –uzsolt Oct 21 '11 at 15:17 5 How do these prevent the messages from displaying? –StackOverflowNewbie Oct 21 '11 at 21:36 7 You must turn debug off for database in config/database.php -> $db['default']['db_debug'] = FALSE; –decebal Dec 12 '12 at 12:47 8 Why is not possible to use Exception instead :-( ? –Thomas Decaux Mar 8 '13 at 11:39 17 These methods have been removed in CodeIgniter version 3. Use $this->db->error() instead. (see codeigniter.com/user_guide/database/…) –mxgr Jul 26 '15 at 11:17 | show 2 more comments up vote 15 down vote Maybe this: $db_debug = $this->db->db_debug; //save setting $this->db->db_debug = FALSE; //disable debugging for queries $result = $this->db->query($sql); //run query //check for errors, etc $this->db->db_debug = $db_debug; //restore setting share|improve this answer answered Jun 18 '13 at 6:1
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings codeigniter try catch and policies of this site About Us Learn more about Stack Overflow codeigniter error handling example the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation
Codeigniter Disable Database Errors
Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it http://stackoverflow.com/questions/7843406/codeigniter-how-to-catch-db-errors only takes a minute: Sign up CodeIgniter SQL query error handling up vote 0 down vote favorite 1 At this moment i access my posts like this http://localhost/post/174565/ and everything works fine, but when i am trying to access them like this http://localhost/post/1745s65/ i am getting error Error Number: 1054 Unknown column '1745s65' in 'where clause' SELECT * FROM posts http://stackoverflow.com/questions/15724584/codeigniter-sql-query-error-handling WHERE id = 1745s65; Filename: D:\Localhost\Apache\htdocs\code\system\database\DB_driver.php Line Number: 330 i understand why it is there, but how to handle it? For example my users don't need to see SQL query, and i want to show them 404 page instead of this block. php sql codeigniter error-handling share|improve this question asked Mar 30 '13 at 23:17 Nerfair 1,10232039 post your code that queries the db based on the url. –Vassilis Barzokas Mar 30 '13 at 23:19 for what you need it? post is not about debuging sql query, but handling errors :) –Nerfair Mar 30 '13 at 23:42 1 to see the way that you parse the query. Normally, if you used active record correctly you should not see the above error. –Vassilis Barzokas Mar 30 '13 at 23:43 Ahh, ok, here it is pastebin.com/aPt7VYuJ –Nerfair Mar 30 '13 at 23:45 add a comment| 3 Answers 3 active oldest votes up vote 1 down vote accepted Try this code: public function getPostData($iPostId) { $sqlQuery = $this->db->get_where('posts', array('id' => $iPostId)); $aResult = $sqlQue
full version with proper formatting. RastoStric02-23-2015, 04:03 AM I am aware of the discussions on this topic in the CI forum, StackOverflow and elsewhere. I tried to do my research error handling carefully but it seems to me, that I did not find a proper answer. The question is how to handle database transaction errors and not to loose the error details. The query error codeigniter CI guide suggested way is PHP Code: $this->db->trans_start();
$this->db->query('ANSQLQUERY...');
$this->db->query('ANOTHERQUERY...');
$this->db->trans_complete();
if($this->db->trans_status()===FALSE)
{
//generateanerror...