'OR Like' MySQL - Maybe a bug? |
[eluser]N3XT0R[/eluser]
Hello guys, i am trying currently to get a searching result with a query created by the active records of CI. here is the sourcecode part that i have implemented: Code: $this->db->select("portierung.portid, status, IFNULL(portierungstermin, '-') as portierungstermin, portierungskennung, carriername, IF(msncancel=1,'Ja','Nein') as msncancel, vorname, nachname, type", FALSE); So i am trying to get after the first "where" statement a "or_like" statement. The result of the above sourcecode is: Code: SELECT portierung.portid, status, IFNULL(portierungstermin, '-') as portierungstermin, portierungskennung, carriername, IF(msncancel=1, 'Ja', 'Nein') as msncancel, vorname, nachname, type Now im a little bit confused, because i wrote the "or_like" statement after the where statement in my sourcecode. CI seems to ignore this line and compile the Active record with a "like" and not a "OR xyz LIKE '%m%'". But i would need a "or_like" to run my query successfull. Yep, i can take the standard query to solve the problem. But maybe there are a more ideal solution. I am using the Version 2.1.3.
[eluser]N3XT0R[/eluser]
I got a solution, maybe not the best, but currently i think is every solution better: CI_DB_active_record Class changes: Code: //Declaring and initialization of $ar_or_like Only done changes for select, this solution is not working for replace into or anything else. Maybe it is helpful for another person, too.
[eluser]Syllean[/eluser]
The user guide says that or_like() is identical to like() except that multiple instances are joined by OR, you didn't have a like first so the first instance is joined with and.
[eluser]jvicab[/eluser]
This is due to CI doesn't enclose the items in OR section between parenthesis so if the query has AND or other statements the operator's precedence is not what we want. I have two solutions for this, which I have posted on my blog (www.jvicab.com/blog/articledetails/12). One of them is adding two functions to DB_active_rec.php (one to deal with or_where and another for or_like. both have the same problem) which properly encloses the OR items. The other is to use native CI where() (or like()) function to build the query as we want. This is the functions I added to my DB_active_rec.php: Code: function like_brackets() If you need more info, you can visit the ULR I provided or email me. |
Welcome Guest, Not a member yet? Register Sign In |