[Qual] Mysqli: set charset with recommended method

This commit is contained in:
Raphaël Doursenaud 2015-12-17 21:10:14 +01:00
parent 7fd2cbea49
commit daa3ce3591
2 changed files with 18 additions and 14 deletions

View File

@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2006-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
/* Copyright (C) 2006-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -417,8 +418,14 @@ function backup_tables($outputfile, $tables='*')
global $errormsg;
// Set to UTF-8
$db->query('SET NAMES utf8');
$db->query('SET CHARACTER SET utf8');
if(is_a($db, 'DoliDBMysqli')) {
/** @var DoliDBMysqli $db */
$db->db->set_charset('utf8');
} else {
/** @var DoliDB $db */
$db->query('SET NAMES utf8');
$db->query('SET CHARACTER SET utf8');
}
//get all of the tables
if ($tables == '*')

View File

@ -4,6 +4,7 @@
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -115,11 +116,9 @@ class DoliDBMysqli extends DoliDB
$clientmustbe='';
if (preg_match('/UTF-8/i',$conf->file->character_set_client)) $clientmustbe='utf8';
if (preg_match('/ISO-8859-1/i',$conf->file->character_set_client)) $clientmustbe='latin1';
if ($this->db->character_set_name() != $clientmustbe)
{
$this->query("SET NAMES '".$clientmustbe."'", $this->db);
//$this->query("SET CHARACTER SET ". $this->forcecharset);
}
if ($this->db->character_set_name() != $clientmustbe) {
$this->db->set_charset($clientmustbe);
}
}
else
{
@ -141,11 +140,9 @@ class DoliDBMysqli extends DoliDB
$clientmustbe='';
if (preg_match('/UTF-8/i',$conf->file->character_set_client)) $clientmustbe='utf8';
if (preg_match('/ISO-8859-1/i',$conf->file->character_set_client)) $clientmustbe='latin1';
if ($this->db->character_set_name() != $clientmustbe)
{
$this->query("SET NAMES '".$clientmustbe."'", $this->db);
//$this->query("SET CHARACTER SET ". $this->forcecharset);
}
if ($this->db->character_set_name() != $clientmustbe) {
$this->db->set_charset($clientmustbe);
}
}
}