I tried to select using the code below, but an error occurred.
I'd like to run a SQL query by connecting specific parameters from another variable to a SQL statement. Is there a good way?
error messages:
ErrorException:Anon-number value encountered in file
code:
$test=config('const.TEST');//(int)3
$sql="SELECT* FROM TEST WHERE col="+$test;
\DB::select($sql);
It's very basic, so I recommend you to go around the manual first.
Basically, using the Query Builder instead of raw SQL is more like a framework.
$rows=DB::table('TEST') ->where('col', $test)->get();
To write raw SQL:
$rows=DB::select('SELECT* FROM TEST WHERE col=?', [$test]);
© 2024 OneMinuteCode. All rights reserved.