DB Active Record: where / or_where return different result |
[eluser]tkaw220[/eluser]
Hi, When working with Active Record, I found below issue: 1) Code: $q = $this->db Query: Code: SELECT * FROM (`products`) WHERE `format` = 'reader' OR `format` = 'reader with 3D goggles' ORDER BY `brand`, `format`, `title` asc Return products properly. 2) Code: $q = $this->db Query: Code: SELECT * FROM (`products`) WHERE `format` = 'reader' OR `format` = 'reader with 3D goggles' ORDER BY `brand`, `format`, `title` asc Return only products match the second parameter, which is reader with 3D goggles. I do not understand how two codes generated one same SQL query, but return result differently. Would appreciate if someone could clarify this. Thank you for your time.
[eluser]toopay[/eluser]
Your second query should returning different SQL statement, something like Code: SELECT * FROM (`products`) WHERE `format` = 'reader' OR `format` = 'reader' OR `format` = 'reader with 3D goggles' ORDER BY `brand`, `format`, `title` asc
[eluser]tkaw220[/eluser]
Hi toopay, Unfortunately, My second query return the same query as the first code. I copied the result directly from my web browser. By the way, I am using CI 2.0.2.
[eluser]toopay[/eluser]
To check all the db object, in your controller, Code: var_dump($this->db); Code: ->where('format', 'reader') Code: ->where('format', 'reader') Post your sql dump file here, so anyone can check that. Because if it goes like you said, it can considered as inconsistent or bug.
[eluser]tkaw220[/eluser]
Hi toopay, Thank you for your time. Firstly, I apologize for my huge mistake. The second code should read: Code: $q = $this->db The sql dump for first code: Code: array And the sql dump for the second code: Code: array Again, the first code return both reader and reader with 3D goggles, whereas the second code return only the reader with goggles. I am very sorry for my mistake in my first post. Thank you.
[eluser]toopay[/eluser]
[quote author="tkaw220" date="1307016013"]Hi toopay, Thank you for your time. Firstly, I apologize for my huge mistake. The second code should read: Code: $q = $this->db [/quote] Your above last query, since there are no "->where" statement before "->or_where" statement, should generates Code: SELECT * FROM (`products`) WHERE `format` = 'reader with 3D goggles' ORDER BY `brand`, `format`, `title` asc Code: array( Code: // remember, your passed array is "array('format' => 'foo', 'format' => 'bar')" In addition, for your convenience in debugging database query instance, you can print out the query, by put $this->db->queries on your controller which calls the model, something like this : Code: // On your controller
[eluser]tkaw220[/eluser]
Hi toopay, Now I got it all. Thank you very much for the detailed explanation. But I couldn't find $this->db->queries inside CI help. Is it an undocumented function? In the meantime, please allow me to query on your Proxy Library. Previous I came across with an issue which I tried to describe in short below: 1) My shopping cart sent _POST values via cURL to payment gateway which I believe does not support REST. The payment gateway received all _POST values successfully, but it does not fully redirect to their web site (where the URL is stick on my domain, while displaying partial of their page) >>> more detail here http://ellislab.com/forums/viewthread/187584/. 2) Can I solve this problem with your library since your library utilize pure PHP, not cURL?
[eluser]toopay[/eluser]
There are other member which request POST feature at my proxy library, since for now it just support GET. But i'm really out of time for these months, and that extra feature should wait until i have some free time. But related with your problem with gateway, i'm sure there are some workaround for it, with cURL. Digging around at curl.haxx.se, and you should able to find a solution for your (specific) problem. If you cant achieve something with cURL, then you're out of luck, since cURL is the most fancy stuff for to connect and communicate to many different types of servers with many different types of protocols, in PHP. If likened to the building, my lib is like a house, while the cURL is a 20th floor building. I create that library, just for portability and simplicity reasons (means, it is for someone who doesnt have curl extension installed). Beyond that, in fact nothing could be achieved with my Proxy Library, if that person cant achieve with cURL. Because, in the bottom of all both building, they have same fondation. It's just that, the proxy library could be an alternative for people who like portability, simplicity and some kind of "primitiveness" attraction on their code ;-)
[eluser]tkaw220[/eluser]
Hi toopay, Well noted. I will keep an eye on the development of your library. Meanwhile, I couldn’t find $this->db->queries inside CI help. Is it an undocumented function? Again, thank you.
[eluser]toopay[/eluser]
tkaw220, you shouldnt worried about that at all. Since all of these, is about Object Oriented approach, then you can access all CI super object, and sub-object. When you put '$this' on some controller, actually it represent CI super object. |
Welcome Guest, Not a member yet? Register Sign In |