How to get MYSQL version Hello,
is there a way to get the MYSQL version like that
mysqli_get_server_info()
What about doing a RAW query for the version?
SHOW VARIABLES LIKE "%version%";
Sorry for bringing this up again, but I found myself googling to this answer multiple times and found this solution to be easier:
$results = DB::select( DB::raw("select version()") );
$mysql_version = $results[0]->{'version()'};
$mariadb_version = '';
if (strpos($mysql_version, 'Maria') !== false) {
$mariadb_version = $mysql_version;
$mysql_version = '';
}
Now, this will check whether MariaDB is used or MySQL with Laravel.
$mysql = DB::select('select version()')[0]->{'version()'};
Since Laravel 9 you can use the DB::scalar() method:
$mysql_version = DB::scalar('select version()');
@mvnrsa Just what I was looking for -- mucho thanks :)
<ul class="text-center mb-2">
@php
$results = DB::scalar('select version()');
@endphp
<li>PHP: {{ phpversion() }}</li>
<li>Laravel: {{ app()->version() }}</li>
<li>MySQL: {{ print_r($results) }}</li>
</ul>
@ZermattChris It's considered bad practice to have calls to the database inside your blade views, I suggest moving that call to your controller instead and pass the variable from there.
Please sign in or create an account to participate in this conversation.