Table of contents

Get MySQL Version in Laravel

In this post, I will share with you how to get the MySQL Version using Laravel. Lately, I need to determine what MySQL version I'm using and maybe you need it also.

 

Here is the code below:

 

Our controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
    public function index() 
    {
        $results = \DB::select( \DB::raw('SHOW VARIABLES LIKE "%version%"') );

        print_r($results);die;
    }
}

 

The results:

Array
(
    [0] => stdClass Object
        (
            [Variable_name] => in_predicate_conversion_threshold
            [Value] => 1000
        )

    [1] => stdClass Object
        (
            [Variable_name] => innodb_version
            [Value] => 10.4.21
        )

    [2] => stdClass Object
        (
            [Variable_name] => protocol_version
            [Value] => 10
        )

    [3] => stdClass Object
        (
            [Variable_name] => slave_type_conversions
            [Value] => 
        )

    [4] => stdClass Object
        (
            [Variable_name] => system_versioning_alter_history
            [Value] => ERROR
        )

    [5] => stdClass Object
        (
            [Variable_name] => system_versioning_asof
            [Value] => DEFAULT
        )

    [6] => stdClass Object
        (
            [Variable_name] => tls_version
            [Value] => TLSv1.1,TLSv1.2,TLSv1.3
        )

    [7] => stdClass Object
        (
            [Variable_name] => version
            [Value] => 10.4.21-MariaDB
        )

    [8] => stdClass Object
        (
            [Variable_name] => version_comment
            [Value] => mariadb.org binary distribution
        )

    [9] => stdClass Object
        (
            [Variable_name] => version_compile_machine
            [Value] => x64
        )

    [10] => stdClass Object
        (
            [Variable_name] => version_compile_os
            [Value] => Win64
        )

    [11] => stdClass Object
        (
            [Variable_name] => version_malloc_library
            [Value] => system
        )

    [12] => stdClass Object
        (
            [Variable_name] => version_source_revision
            [Value] => 4902b0fdc91cc6dc169dd2322daf966a2eeafdd8
        )

    [13] => stdClass Object
        (
            [Variable_name] => version_ssl_library
            [Value] => WolfSSL 4.8.0
        )

)

 

Reference: https://stackoverflow.com

 

Thanks for visiting. I hope it helps :)