Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
How to check database connection array

So basically i'm building an application where the customer wants to connect to his own databases, and I made a form where he can submit his credentials

connectionForm: this.$inertia.form({
                driver: 'mysql',
                name: '',
                host: '',
                port: 3306,
                username: '',
                password: '',
                database: '',
                charset  : 'utf8',
                collation: 'utf8_unicode_ci',
                prefix: '',

            })

Array received in laravel controller

array:10 [▼
  "driver" => "mysql"
  "name" => "Connection"
  "host" => "127.0.01"
  "port" => 3306
  "username" => "root"
  "password" => null
  "database" => "clinic"
  "charset" => "utf8"
  "collation" => "utf8_unicode_ci"
  "prefix" => null
]

And I want to create a function to check if the submitted database credentials can make a connection to his database, so far I haven't found a way to do it by passing the credentials array. I've tried this way

if (DB::connection($request->validated())->getDatabaseName())
        {
            ray('The connection was successfull');
            return 'Connected to the DB: ' . DB::connection('myDamnDbConnection')-getDatabaseName();
        }

but it requires a string, not an array. Is there any way to do this?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Add the database configuration to your config as a new entry and then use that:

config([ 'database.connections.temp' => $request->validated() ]);
DB::connection('temp')->connect(); // Would throw an exception if it fails 
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!