How To Check MySQL Server Version in Laravel Tutorial

Reading Time: 3 minutes
638 Views

Inside this article we will see the concept i.e How To Check MySQL Server Version in Laravel Tutorial. Article contains the classified information about How to check MySQL version number using Laravel concept.

Whenever you work with MySQL database, you must know which version you are working with. You can know this version direct from PhpMyAdmin interface, Server Commands, etc but this can be done by Laravel code as well.

Read More: JQuery Form Validation For Confirm Password Tutorial

Let’s get started.

Laravel Installation

Open terminal and run this command to create a laravel project.

composer create-project laravel/laravel myblog

It will create a project folder with name myblog inside your local system.

To start the development server of laravel –

php artisan serve

URL: http://127.0.0.1:8000

Assuming laravel already installed inside your system.

How To Check MySQL Server Version

To see the details of database server and it’s version we will use DB facade.

//...
use Illuminate\Support\Facades\DB;

Route::get("details", function () {

    $sqlVersion = DB::select(DB::raw('SHOW VARIABLES LIKE "%version%"'));
    print_r($sqlVersion);
    die;
});

//...

Application Testing

Run this command into project terminal to start development server,

php artisan serve

URL: http://127.0.0.1:8000/details

Read More: How To Disable Browser Back Button Using Javascript

Output

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
        )
)  

We hope this article helped you to learn How To Check MySQL Server Version in Laravel Tutorial in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more