Tema: Re: [HEPL]: Unicode ir Ubuntu LTS
Autorius: Tester
Data: 2020-11-03 10:16:14
Taip, reikia naudoti SET NAMES, tik manau, kad šita problema prieš n metų 
turėjo pasireikšti.

Jei nenaudojam PDO tai prisijungimas turi būti maždaug toks:

@$link = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD)
      or die('Could not connect: ' . mysqli_connect_error());
  mysqli_select_db($link, DATABASE_NAME) or die('Could not select 
database');
  $query="SET NAMES utf8";//fix incorrect chars when MySQL 5.0 default 
charset!=utf8
  $result = mysqli_query($link,$query) or die('could not set utf8 encoding' 
.. mysqli_error($link));


Jei naudojam PDO tai taip:
try {
    $dbh = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, 
DB_USER,DB_PASSWORD,
                array(
                PDO::ATTR_PERSISTENT => true,
                PDO::ATTR_ORACLE_NULLS=>PDO::NULL_EMPTY_STRING, //for all 
drivers, not oracle only
                PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                PDO::ATTR_EMULATE_PREPARES   => false,
                //PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false, //f you are 
selecting a really huge amount of data, always set - causes exceptions
                PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
                    ));
    //$dbh->query('SET NAMES utf8');
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}