You are mixing query Builder code with DB facade code you don't need the raw in there.
Look straight at the database chapter, the select example.
Why is this query working on MySQL Workbench but not on Lumen?
Query:
SELECT * FROM domain_apps WHERE date(created_at) = "2021-02-04" and macaddress= "BC-2D-EF-1C-DB-AB";
I'm getting records.
Lumen code:
$results = DB::select( DB::raw('SELECT * FROM apps WHERE date(created_at) = "2021-02-04" and macaddress= "BC-2D-EF-1C-DB-AB"') );
Result is empty.
You are mixing query Builder code with DB facade code you don't need the raw in there.
Look straight at the database chapter, the select example.
I actually tried on Eloquent but same result so I experimented on the Raw.
Example from docs:
$users = DB::select('select * from users where active = ?', [1]);
Did you import the DB facade at top of controller, did you set up your configuration for the database.
If you do like the example and it doesn't work you have a missed configuration somewhere.
Did you import the DB facade at top of controller, = Yes
did you set up your configuration for the database. = Yes, I have a lot of function already working but this one is giving me the headache.
If you do like the example and it doesn't work you have a missed configuration somewhere.
I've tried it like this
$results = DB::select( 'SELECT * FROM domain_apps WHERE date(created_at) = "2021-02-04" and macaddress= "BC-2D-EF-1C-DB-AB"');
Still no result.
Originally before the RAW SQL. I've have this:
$results = DB::table('domain_apps')
->wheredate('created_at', '2021-02-04')
->where('macaddress', 'BC-2D-EF-1C-DB-AB')
->get();
Again, no result.
See if you get results with dd.
$results = DB::table('domain_apps')
->wheredate('created_at', '2021-02-04')
->where('macaddress', 'BC-2D-EF-1C-DB-AB')
->get();
dd($results);
Or see what you get in the response in the network tab.
Everything looks correct it's as though you need to check your configuration, also did you run PHP artisan config: clear
I would imagine Lumen has that command also, I use laravel.
But suggestion, have you thought about just using Laravel.
nothing on the dd result.
There is no php artisan config:clear on Lumen only php artisan cache:clear
Yes, I might just have to convert it to full Laravel.
Try with each WHERE separately and you should then be able to see which is not working. Perhaps the where date behaves differently on lumen?
It's working individually but not when both. On date, I've tried converting it to Carbon date and still won't work.
Are you getting the same result back if you use each where separately?
Not same result because I'm querying different fields.
Does the result you are expecting appear in both queries?
Different data in different databases, so what do you want? A miracle?
thats where I was getting to. unless there was a result which matches both where statements you'll get no results, as @delphinoy seemed to be getting.
I've mentioned different field not different database
@automica asked me to check the result each separately
Yes, getting the result I want for each but not working when combined although the same query is working on MySQL workbench. Thanks for your time.
@automica they said it's working with a direct query in workbench. So you would think query in laravel would give same results. @delphinoy try getPdo().
$results = DB::select("SELECT * FROM apps WHERE created_at = ? and macaddress= ?",["2021-02-04","BC-2D-EF-1C-DB-AB"']);
Please or to participate in this conversation.