How can I use findAll with select in model? |
Hi!
I try to like this, but it's error of SQL syntax. PHP Code: $model = model('MyModel'); Im trying to use builder, like this PHP Code: $builder = $model->builnder(); the error message is (SELECT COUNT(*) FROM TABLE WHERE IDX = ....' at line 1 Can I use select method with findAll in model? if I can't, what I do another option? Thank you
Code: // Method inside your controller This is tested and produces a result set without error. However, after getting your code to work you would be better off creating a method in your model and returning your results rather than manipulating the database logic from within your controller.
find()
Returns a single row where the primary key matches the value passed in as the first parameter: $user = $userModel->find($user_id); The value is returned in the format specified in $returnType. You can specify more than one row to return by passing an array of primaryKey values instead of just one: $users = $userModel->find([1,2,3]); If no parameters are passed in, will return all rows in that model’s table, effectively acting like findAll(), though less explicit. Please read the docs. |
Welcome Guest, Not a member yet? Register Sign In |