active record where field IS NULL error? |
[eluser]KrizzAngel[/eluser]
with this code: Quote:$this->db->where('name',$this->input->post('name'));i got this error when running it: Quote:A Database Error Occurred any problem from my code?? is NULL not allowed on 'where' clause in AR??
[eluser]BaCeTo[/eluser]
Code Igniters's main db handler (i.e. Active Record, unless you have installed something else, like IgniterQuery for example) will automatically try to escape the parameters. In terms of security this is fine. But in your case, the NULL value, escaped will be implemented as " ... WHERE `section` = 'NULL' ... " Thus you will not have the results you expect ![]() Anyway, there is a workaround. There is a third parameter of the method db::where with a default value of false. If set to true it will pass the data unescaped. Try again the query, but altered like that: $this->db->where('section IS NULL', '', true); Thisway section will be matched against NULL values, not the "NULL" string itself. The second parameter will be passed as an unescaped empty string, which will affect nothing. If you take a look at the documentation of ActiveRecord you will find some helpful explanations ![]() http://ellislab.com/codeigniter/user-gui...tml#select Best of luck with your coding. Greetings BaCeTo
[eluser]KrizzAngel[/eluser]
hmm.. that doesnt work either.. huhu.. originally i got this code: Quote:$query =$this->db->query("select * from tblprof where name='".$this->input->post('name')."' AND section IS NULL "); *note the code above is from my other post it seems that the IS NULL function isnt working coz my code always executing insert query, thats why i switched it to AR but no luck.. i got db error.. ![]()
[eluser]Armchair Samurai[/eluser]
Two things: first, you haven't specified the table you're running the query on. Secondly, you need to set the third parameter to FALSE, not TRUE, if you want to avoid CI escaping the clause. Code: $this->db->where('name', $this->input->post('name'));
[eluser]KrizzAngel[/eluser]
ok so i use my AR again lol.. didnt notice that i forgot to select a table.. when everything seems right still it doesnt work.. Quote:// $query =$this->db->query(“select * from tblprof where name=’”.$this->input->post(‘name’).”’ AND section IS NULL “); the code still executes insert query.. |
Welcome Guest, Not a member yet? Register Sign In |