Problems with foreign key |
[eluser]DarthVinsus[/eluser]
Hello people, how can I solve this problem with codeigniter? Code: A Database Error Occurred
[eluser]DarthVinsus[/eluser]
I half solved the problem Code: if ($this->db->_error_message()){ only need to identify the error num and associate with a more clientside message
[eluser]Dam1an[/eluser]
Do you want the delete to fail in this case, or do you want it to delete the constraint rows, and then delete this row?
[eluser]DarthVinsus[/eluser]
I want the delete fail, and it fails, but I should give the client an understanding human-like message. I have solved it with a library Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); and I can use it where I will. Code: $this->load->library('myutils'); What I only need is a list of the error number and associate with a better human-like message
[eluser]Dam1an[/eluser]
Instead of doing the check for what error type it is in the model (or where ever you use it) I would suggest setting it as a string in the library so you can then just do Code: $error = $this->myutils->error; I'd also recommend using a switch which is faster then a whole series of if else statement (and having the more common errors first so you exit the lookup asap) As for where you can get these... no idea, you tried Google?
[eluser]Cro_Crx[/eluser]
Dam1an: I think in other programming languages switch-case statements are usually quicker than using elseif. Although in PHP they seem to perform almost exactly the same. http://www.phpbench.com/ (4th test from the top). In that particular test else if was a tad quicker. Although putting the most common errors first is defiantly good design and speeds up the program a lil
[eluser]Dam1an[/eluser]
[quote author="Cro_Crx" date="1242425270"]Dam1an: I think in other programming languages switch-case statements are usually quicker than using elseif. Although in PHP they seem to perform almost exactly the same. http://www.phpbench.com/ (4th test from the top). In that particular test else if was a tad quicker. Although putting the most common errors first is defiantly good design and speeds up the program a lil [/quote] Really?!?! *Looks at benchmarks* I guess this is comming from a primarily Java background, and the difference there was much quicker. It might be to do with the fact in Java, a switch only works on numbers and chars (not strings) so they can be optimised more then a switch on strings could in PHP?
[eluser]Cro_Crx[/eluser]
We were always taught to use switch case when doing C programming. That website is really good for optimizing your code but I'm always going to use foreach no matter how slow it is :S |
Welcome Guest, Not a member yet? Register Sign In |