2

I am trying to create a login system in laravel. I've updated env. file with a database called kokodb. However, when I run this code 'php artisan migrate' in cmd, I came up with the following error:

In Connection.php line 647:

SQLSTATE[HY000] [2054] Server sent charset unknown to t he client. Please, report to the developers (SQL: selec t * from information_schema.tables where table_schema = kokodb and table_name = migrations)

In Connector.php line 68:

SQLSTATE[HY000] [2054] Server sent charset unknown to t he client. Please, report to the developers

In Connector.php line 68:

PDO::__construct(): Server sent charset (255) unknown t o the client. Please, report to the developers

Can you please help me. I did not find any solution to this problem anywhere else.

Your Common Sense
  • 152,517
  • 33
  • 193
  • 313
ALBADI
  • 165
  • 2
  • 13
  • What version of PHP and Laravel is this? – Travis Britz Oct 26 '18 at 06:14
  • it was version 5. and now it is it is 7.2.11. but this does not solve the problem – ALBADI Oct 26 '18 at 07:23
  • To clarify, it was PHP 5 and then you installed PHP 7.2.11? If so, have you verified that both your webserver and your command line are now using the new php version? – Travis Britz Oct 26 '18 at 07:29
  • did you find solotion? – Adam Kozlowski Oct 26 '18 at 09:18
  • It seems that upgrading PHP has solved the charset problem. however, now I am facing another problem when I am trying to migrate. SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = kokodb andtable_name = migrations). – ALBADI Oct 26 '18 at 09:34

5 Answers5

3

What version of PHP are you using?

According to PHP's bugtracker, this should be fixed as of 7.0.19, 7.1.5, and 7.2.0.

https://bugs.php.net/bug.php?id=74461

Arun's links mention a solution of changing the server charset back to utf8, but utf8mb4 really is preferable because it offers full unicode support.

Travis Britz
  • 4,100
  • 1
  • 13
  • 29
2

make sure you create a database first. then, Make sure that you have correct params when it comes to the database in your .env file. Here scenario for localhost:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306 (this can be different when database changed.)
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_pass

also run : php artisan config:cache to clear cache.

it work for me.. good luck

avishka
  • 21
  • 1
1
<?php

$servername = "localhost";

$username = "root";

$password = "";



try{

    // servername and database name
    // my port no is 3307 check your's
    $conn = new PDO('mysql:host = $servername; dbname=project1; ', $username, $password );


    // set the PDO error mode
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected Successfully";

}
catch(PDOException $e){

    
    echo "Your Connection failed: ".$e->getMessage();
}


?>
Syscall
  • 16,959
  • 9
  • 22
  • 41
  • Thank you for this code snippet, which might provide some limited, immediate help. A [proper explanation](https://meta.stackexchange.com/q/114762/9193372) would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made. – Syscall Mar 16 '21 at 13:09
0

Make sure that you have correct params when it comes to database in your .env file. Here scenario for localhost:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_pass

After any change in .env use php artisan config:cache in console

Also in config/database.php set

    'charset'     => 'utf8mb4',
    'collation'   => 'utf8mb4_unicode_ci',
    'modes'       => [
                'ONLY_FULL_GROUP_BY',
                'STRICT_TRANS_TABLES',
                'NO_ZERO_IN_DATE',
                'NO_ZERO_DATE',
                'ERROR_FOR_DIVISION_BY_ZERO',
                'NO_ENGINE_SUBSTITUTION',
            ],

Then also: php artisan config:cache

Good luck!

Adam Kozlowski
  • 3,978
  • 1
  • 23
  • 38
  • I wouldn't recommend `config:cache` during development – Travis Britz Oct 26 '18 at 06:30
  • Hey man, you wouldn't recommend config:cache during development? Maybe you will give us a reason? – Adam Kozlowski Oct 26 '18 at 06:31
  • Of course, sorry. If you are *already* caching config then yes, you need to run `config:cache` again (and during deployment). For dev, when config options change often, it's easy to forget that step (and the benefits of optimizing your local machine are small). It can lead to hours of "why won't my change work?" kinds of debugging (the first time). On Stackoverflow I expect there to be a lot of inexperienced Laravel devs who wouldn't remember that they'd run `config:cache` a week ago when they were running commands from suggested fixes. One less pothole for them to step in. – Travis Britz Oct 26 '18 at 06:47