I have a problem with writing a PHP code line with Laravel 8. The following SQL line works in console:
SELECT archive.license('{"CC-BY-NC-ND-4.0"}');
The next line with Laravel does not work:
DB::select('SELECT archive.license(\'{"' . $code . '"}\')')
Illuminate\Database\QueryException : SQLSTATE[42883]: Undefined function: 7 ERREUR: la fonction archive.license(unknown) n'existe pas LINE 1: SELECT archive.license('{"CC-BY-NC-ND-4.0"}')
An idea of the way of writing this? Thanks
CodePudding user response:
You can run a raw select query using the DB facade. But remember to bind your parameters.
Try the following:
$params = [
'{"' . $code . '"}'
];
DB::select('SELECT archive.license(?)', $params);