Can you use named parameters in Laravel Rloquent

I use Oracle as a database tier, but the problem is that the oracle through OCI8 (I created the PDO user space driver) only supports named parameters in SQL statements and does not support positional parameters. (For example, using several?)

In the database, this is Laravel Eloquent, which generates SQL, but I can not find any documentation on how to override the design of parameters.

I would like to be able to create named parameters in the form of ": name" instead of placing multiple "?" at the time of the request.

Can this be done? I assume this has something to do with database grammar classes ...

+2
sql oracle php pdo laravel
source share
1 answer

Well, if someone has a better solution, let him introduce it or perhaps tell me what might be wrong in my workaround. I replace all the "?" with ": autoparam" with a parameter increment creating ": autoparam0", ": autoparam1", ": autoparam2", etc.

//Replace ? with a pseudo named parameter $newStatement = null; $parameter = 0; while($newStatement !== $statement) { if($newStatement !== null) { $statement = $newStatement; } $newStatement = preg_replace('/\?/', ':autoparam'.$parameter, $statement, 1); $parameter++; } $statement = $newStatement; 

Then, when I get a request to bind a parameter from PDO, I check if this parameter is numeric. In most languages, as far as I know, numeric indices are invalid identifiers, so I can safely assume, at least for my driver for Windows PDO, to replace the name of the numeric parameter:

  //Replace the first @oci8param to a pseudo named parameter if(is_numeric($parameter)) { $parameter = ':autoparam'.$parameter; } 

This works now, I need to do more tests with laravel to see if the problem appears in a different score, but so far it seems complete ...

+1
source share

All Articles