georgerobbo Posted April 9, 2011 Share Posted April 9, 2011 Hello I'm developing a Model-View-Controller framework for my personal learning curve. I've created an active record class and I've got stuck when using variables in a where clause. My problem is this: When, in a where statement, you want to find the Users with the first name Mike, you might write SELECT Firstname, Surname FROM Users WHERE Firstname = 'Mike' Where Mike is enclosed with quotation marks. When you're comparing entities quotation marks shouldn't be used. For example, SELECT Firstname, Surname, OrderTitle FROM Users, Orders WHERE Firstname = 'Mike' AND Users.Firstname = Orders.Firstname So when using variables in my where statements, like $Name = Mike $this->Where(Firstname',$Name); $this->Where('Users.Firstname','Orders.Firstname'); How do I differentiate, in my function Where() when to enclose the string with quotation marks, i.e when it is a (Table.Entity) rather than a constant. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/233202-variables-in-the-model-mvc/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 9, 2011 Share Posted April 9, 2011 The method (pun intended) by which you build the syntax of your query should be separate and different from the method by which you put program driven data values into the query statement. I would use place holders for the variable data, i.e. ? and use a different class method to build the query syntax from the class method used to populate any variable data in that query. Quote Link to comment https://forums.phpfreaks.com/topic/233202-variables-in-the-model-mvc/#findComment-1199293 Share on other sites More sharing options...
ignace Posted April 10, 2011 Share Posted April 10, 2011 .. and use a different class method to build the query syntax from the class method used to populate any variable data in that query. Like: $this->Join('Orders', 'Users.Firstname = Orders.Firstname'); An ActiveRecord class is not a Query Object (or Interpreter). The Active Record defines behavior specific to a record. class User { public function verify($verificationCode) { /* after successfull validation, activates the user account */ } } Quote Link to comment https://forums.phpfreaks.com/topic/233202-variables-in-the-model-mvc/#findComment-1199578 Share on other sites More sharing options...
georgerobbo Posted April 10, 2011 Author Share Posted April 10, 2011 Ah! Thanks. I usually use where statements to join my tables. Will do! Quote Link to comment https://forums.phpfreaks.com/topic/233202-variables-in-the-model-mvc/#findComment-1199584 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.