Merge pull request #4256 from GPCsolutions/dolibarr-mysqli
[Qual] mysqli code review
This commit is contained in:
commit
d7847a8ec8
@ -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 == '*')
|
||||
|
||||
@ -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
|
||||
@ -75,7 +76,6 @@ class DoliDBMysqli extends DoliDB
|
||||
$this->ok = false;
|
||||
$this->error="Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver.";
|
||||
dol_syslog(get_class($this)."::DoliDBMysqli : Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver.",LOG_ERR);
|
||||
return $this->ok;
|
||||
}
|
||||
|
||||
if (! $host)
|
||||
@ -84,7 +84,6 @@ class DoliDBMysqli extends DoliDB
|
||||
$this->ok = false;
|
||||
$this->error=$langs->trans("ErrorWrongHostParameter");
|
||||
dol_syslog(get_class($this)."::DoliDBMysqli : Connect error, wrong host parameters",LOG_ERR);
|
||||
return $this->ok;
|
||||
}
|
||||
|
||||
// Try server connection
|
||||
@ -96,7 +95,6 @@ class DoliDBMysqli extends DoliDB
|
||||
$this->ok = false;
|
||||
$this->error = $this->db->connect_error;
|
||||
dol_syslog(get_class($this) . "::DoliDBMysqli Connect error: " . $this->error, LOG_ERR);
|
||||
return $this->ok;
|
||||
} else {
|
||||
$this->connected = true;
|
||||
$this->ok = true;
|
||||
@ -115,11 +113,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,15 +137,11 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->ok;
|
||||
}
|
||||
|
||||
|
||||
@ -203,7 +195,7 @@ class DoliDBMysqli extends DoliDB
|
||||
*/
|
||||
function getVersion()
|
||||
{
|
||||
return $this->db->get_server_info();
|
||||
return $this->db->server_info;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -213,7 +205,7 @@ class DoliDBMysqli extends DoliDB
|
||||
*/
|
||||
function getDriverInfo()
|
||||
{
|
||||
return $this->db->get_client_info();
|
||||
return $this->db->client_info;
|
||||
}
|
||||
|
||||
|
||||
@ -381,7 +373,7 @@ class DoliDBMysqli extends DoliDB
|
||||
*/
|
||||
function escape($stringtoencode)
|
||||
{
|
||||
return addslashes($stringtoencode);
|
||||
return $this->db->real_escape_string($stringtoencode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user