Newbie confusion about the database docs |
[eluser]Doug Lerner[/eluser]
What? What? What? $query is just a variable containing the result of the get() method, isn't it? How can it contain the intermediate information that get() uses, which was built up in the previous statements? There is nothing special about the name $query, right? It is just a variable that gets assigned the object which is what is returned from get() I thought. Now I'm more confused than ever. doug
[eluser]Colin Williams[/eluser]
Quote:There is nothing special about the name $query, right? It is just a variable that gets assigned the object which is what is returned from get() I thought. Nothing special at all, just reads well in the code ![]() Nothing magic. Just vanilla OOP
[eluser]Doug Lerner[/eluser]
Well, then I still don't understand where the get() method is getting the information on which it is working, which was my original question. I see there are a series of statements prior to the assignment of the get() results to $query. But what is the association between those statements and the statement where get() is used? Where is the information that is passed to get() stored before the call to get()? What form does it take? Can it be viewed with an echo statement? When is that information reset? That was what my question was - not what get() returns. Thanks, doug
[eluser]Colin Williams[/eluser]
Well, when you call a method like, $this->db->where('id', 1), the $db object stores the 'where' information of the query in a property of the $db object. You can access it directly with $this->db->_ar_where I believe. It does similar things with other methods (like(), join(), orderby(), etc). When you call the get() method, the $db object uses the pieces of the query it has previously stored to build the SQL query and executes it. It also clears out the info it previous stored (unless you instruct it otherwise). Just look at the code if you're really curious.
[eluser]Chris Newton[/eluser]
After each get() call, the statements previous to it are destroyed. So you can Code: // Query 1 Also, I find the following handy to clear a query after I've used all of the data I need from it: $query->free_result(); And this is handy to review the SQL call made after running an Active Record get() call: $myvar=$this->db->last_query(); Those items aren't part of your question, but I thought they'd be useful to point out anyway.
[eluser]m4rw3r[/eluser]
If you only want the SQL, and not the result, use $this->db->_compile_select(); , it will return the sql string.
[eluser]Doug Lerner[/eluser]
Thanks. What I really want is to not learn SQL if possible, and still create, save and read objects. ![]() doug
[eluser]Colin Williams[/eluser]
Quote:Thanks. What I really want is to not learn SQL if possible, and still create, save and read objects. We could tell. SQL is about as mysterious as 3rd grade math, so you might as well just get to know it. |
Welcome Guest, Not a member yet? Register Sign In |