Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

howard_hsiao's avatar

Query outside database with 'between condition

I'm confused at Laravel's query DB. Here is my code:

collect(DB::connection('2ndDB')->select('select avgvalue, logtime from 2ndDB.mytable where logtime =?',array('14:38')));

It does work on and return the right value. However, once I change the SQL statement with 'between' condition, down here:

collect(DB::connection('2ndDB')->select('select avgvalue, logtime from 2ndDB.mytable between logtime =? and ?',array('14:38','15:00')));

It would get error. May I ask how to fix it?

Note: I am query the outside database that the 'mytable' is not declared in the mode/database/migration part. So, I use the (DB:connection()) in this way for query.

0 likes
2 replies
Snapey's avatar
Snapey
Best Answer
Level 122

test the query in another tool. The syntax seems wrong although you have not said what the other database is.

you need a where statement I think

select avgvalue, logtime from 2ndDB.mytable where logtime between ? and ?

howard_hsiao's avatar

Thanks a lot. I guess make a big mistake at all. Anyway, thanks!

Please or to participate in this conversation.