I think the config helper should do the trick:
config('mail.driver'); // should returns for example 'mysql'
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi guys,
What is the best way to determine the current database driver?
Currently using this code in Laravel 5.2:
switch(DB::connection()->getPDO()->getAttribute(PDO::ATTR_DRIVER_NAME))
{
case 'mysql':
//mysql syntax
break;
case 'sqlite':
//sqlite syntax
break;
default:
throw new \Exception('Driver not supported.);
break;
}
In this case I can't just use Eloquent (unfortunately), so I need to be able to dynamically change
syntax for a complex sql query that is not portable between different drivers. i.e: upsert
I just need a quick and dirty way to substitute the sql syntax based on which driver currently connected.
$connection = config('database.default');
$driver = config("database.connections.{$connection}.driver");
Please or to participate in this conversation.