How to set mysql user variable at every new connection in Laravel 5.5?

68
March 15, 2019, at 8:00 PM

Background: We rely heavily on views in our app and one of the ways in which we are looking to optimize them is by parameterization. We've got that aspect all figured out, but in order to make it work, I must be able to set a user parameter for the customer (tenant) id. I want to do this at a base level so that it is set for every single connection.

For example the script I want to run is simply: Set @Param_CustomerId:=1234 where 1234 is the customer id based on the authentication.

Here's the question: Where can I set up code that will get run every time a new MySQL Connection is established?

Answer 1

I think you can run that code in the registerConnectionServices method of a class which would extend the default DatabaseServiceProvider (and use that extended provider instead of the default).

READ ALSO
Mysql adding index for column type text does not improve performance while using select query

Mysql adding index for column type text does not improve performance while using select query

I am using InnoDBFrom this question, I found out that I have to specify the length if I want to add index to columns which type is TEXT

74
How to find cpanel credential? [on hold]

How to find cpanel credential? [on hold]

I am facing a mail server Debian 7Few years ago, roundcube 0

43
How to create mysql container with initial data in kubernetes?

How to create mysql container with initial data in kubernetes?

I want to set initial data(script file which creates database and table) on MySQL of containerI have another pod which will talk with mysql pod and inserts data in the table

60