yajra / pdo-via-oci8

PHP PDO_OCI functions via OCI8 extension
Other
88 stars 61 forks source link

Use oci_new_connect instead oci_connect #137

Open francescoparadisiniva opened 3 months ago

francescoparadisiniva commented 3 months ago

Hi everyone!

I have the following Code but it doesn't work.

DB::connection("oracle")->beginTransaction();
DB::connection("oracle_log")->beginTransaction();
dump(ModelExample::on("oracle")->count()); \\ 10 records
dump(ModelExample::on("oracle_log")->count()); \\ 10 records
ModelExample::on("oracle_log")->insert([
    "column" => "test"
]);
dump(ModelExample::on("oracle_log")->count()); \\ 11 records
dump(ModelExample::on("oracle")->count()); \\ I expect 10 records but i have 11 records

The oracle connection and oracle_log connection have the same configs.

Using the oci_connect function, as stated in the PHP documentation, oci_connect() with the same parameters will return the connection handle returned from the first call. Using Laravel singletons for connections, there should be no problems with an increase in sessions.

My proposal would be to use the oci_new_connect function instead of oci_connect or use a parameter within the config on which function to use.

yajra commented 3 months ago

Looks like a valid use case as defined in oci_new_connect. Maybe we use another config that will trigger this behavior?

Just a rough idea, maybe we can add a 'cached' => false config which will use oci_new_connect if set to false.

Feel free to submit a PR, thanks!