J
J
Jeracsus2019-07-27 21:00:53
PHP
Jeracsus, 2019-07-27 21:00:53

How to change encoding of sql query in OpenServer?

I am querying the database using pdo.

$dsn = 'mysql:host=localhost;dbname=f5_shop';
 $pdo = new PDO($dsn, 'root', '');
$quere = $data['search_request'];
    $sql = 'SELECT * FROM `remont` WHERE `:type` = `:link`';
    $query = $pdo->prepare('SELECT * FROM `remont` WHERE `:type` = `:link`');
    $query->execute(['type' => $type_a, 'link' => $quere]);

But if I enter the Cyrillic alphabet, then I get a krakozyabra instead of Russian letters in the request. I realized that they arise when you try to translate from UTF-8 to WIN-1251. Cyrillic is displayed normally on the site itself. Any "SET NAMES" command does not help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SagePtr, 2019-07-27
@SagePtr

The fact is that the author of OpenServer slipped a trick into the MySQL configs.
In order for the encoding change to work in PDO when using OpenServer, you need to remove the init-connect parameter from the MySQL configs there, which, like a rat, changes the encoding to another without notifying PDO in any way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question