Update mysql

This commit is contained in:
Michael RICOIS 2015-05-25 09:03:44 +00:00
parent d5e6c01aee
commit 2b8c13abe4
2 changed files with 32 additions and 22 deletions

View File

@ -34,7 +34,7 @@ class WDB
{
$this->errorCode = 0;
$this->errorMsg = '';
$fields = implode(array_keys($toAdd), ',');
foreach (array_values($toAdd) as $key=>$array_values)
$tmp[$key]=checkaddslashes($array_values);
@ -81,7 +81,7 @@ class WDB
{
$this->errorCode = 0;
$this->errorMsg = '';
if ($low_priority) {
$query='UPDATE LOW_PRIORITY '.$table.' SET ';
} else {
@ -131,11 +131,11 @@ class WDB
{
$this->errorCode = 0;
$this->errorMsg = '';
if ($low_priority)
$query='DELETE LOW_PRIORITY QUICK FROM `'.$table.'` WHERE '.$where.' LIMIT 1;';
$query='DELETE LOW_PRIORITY QUICK FROM '.$table.' WHERE '.$where.' LIMIT 1;';
else
$query='DELETE FROM `'.$table.'` WHERE '.$where.' LIMIT 1;';
$query='DELETE FROM '.$table.' WHERE '.$where.' LIMIT 1;';
if ($debug) $tdeb=microtime_float();
@ -171,7 +171,7 @@ class WDB
{
$this->errorCode = 0;
$this->errorMsg = '';
$query="SELECT $fields FROM $table WHERE $where;";
if ($debug) $tdeb=microtime_float();
@ -241,7 +241,12 @@ class WDB
} else {
$duree = 'N/D';
}
file_put_contents(LOG_PATH . '/mysql.log', date('Y-m-d H:i:s') ." - ".$query." - ".$this->errorCode.":".$this->errorMsg." - ".$duree."\n", FILE_APPEND);
if ($this->errorCode == 0) {
$msg = date('Y-m-d H:i:s') ." - DEBUG - ".$this->errorCode.":".$this->errorMsg." - ".$query." - ".$duree;
} else {
$msg = date('Y-m-d H:i:s') ." - ERROR - ".$this->errorCode.":".$this->errorMsg." - ".$query." - ".$duree;
}
file_put_contents(LOG_PATH . '/mysql.log', $msg . "\n", FILE_APPEND);
}
/**
@ -251,7 +256,7 @@ class WDB
{
$this->errorCode = 0;
$this->errorMsg = '';
try {
$stmt = $this->db->query($query);
$this->result = $stmt;
@ -307,7 +312,7 @@ class WDB
$nbLignes = count($res);
for($i=0; $i<$nbLignes; $i++) {
$ligne = $res[$i];
//Header
if ($i==0) {
$nbCols = count($ligne);
@ -317,7 +322,7 @@ class WDB
}
fputcsv($fp, $header, $sep, '"');
}
//Content
$fields = array();
foreach ($ligne as $libCol => $col) {
@ -325,7 +330,7 @@ class WDB
}
fputcsv($fp, $fields, $sep, '"');
}
fclose($fp);
return $nbLignes;
}

View File

@ -34,7 +34,7 @@ class WDB
{
$this->errorCode = 0;
$this->errorMsg = '';
$fields = implode(array_keys($toAdd), ',');
foreach (array_values($toAdd) as $key=>$array_values)
$tmp[$key]=checkaddslashes($array_values);
@ -81,7 +81,7 @@ class WDB
{
$this->errorCode = 0;
$this->errorMsg = '';
if ($low_priority) {
$query='UPDATE LOW_PRIORITY '.$table.' SET ';
} else {
@ -131,11 +131,11 @@ class WDB
{
$this->errorCode = 0;
$this->errorMsg = '';
if ($low_priority)
$query='DELETE LOW_PRIORITY QUICK FROM `'.$table.'` WHERE '.$where.' LIMIT 1;';
$query='DELETE LOW_PRIORITY QUICK FROM '.$table.' WHERE '.$where.' LIMIT 1;';
else
$query='DELETE FROM `'.$table.'` WHERE '.$where.' LIMIT 1;';
$query='DELETE FROM '.$table.' WHERE '.$where.' LIMIT 1;';
if ($debug) $tdeb=microtime_float();
@ -171,7 +171,7 @@ class WDB
{
$this->errorCode = 0;
$this->errorMsg = '';
$query="SELECT $fields FROM $table WHERE $where;";
if ($debug) $tdeb=microtime_float();
@ -241,7 +241,12 @@ class WDB
} else {
$duree = 'N/D';
}
file_put_contents(LOG_PATH . '/mysql.log', date('Y-m-d H:i:s') ." - ".$query." - ".$this->errorCode.":".$this->errorMsg." - ".$duree."\n", FILE_APPEND);
if ($this->errorCode == 0) {
$msg = date('Y-m-d H:i:s') ." - DEBUG - ".$this->errorCode.":".$this->errorMsg." - ".$query." - ".$duree;
} else {
$msg = date('Y-m-d H:i:s') ." - ERROR - ".$this->errorCode.":".$this->errorMsg." - ".$query." - ".$duree;
}
file_put_contents(LOG_PATH . '/mysql.log', $msg . "\n", FILE_APPEND);
}
/**
@ -251,7 +256,7 @@ class WDB
{
$this->errorCode = 0;
$this->errorMsg = '';
try {
$stmt = $this->db->query($query);
$this->result = $stmt;
@ -307,7 +312,7 @@ class WDB
$nbLignes = count($res);
for($i=0; $i<$nbLignes; $i++) {
$ligne = $res[$i];
//Header
if ($i==0) {
$nbCols = count($ligne);
@ -317,7 +322,7 @@ class WDB
}
fputcsv($fp, $header, $sep, '"');
}
//Content
$fields = array();
foreach ($ligne as $libCol => $col) {
@ -325,7 +330,7 @@ class WDB
}
fputcsv($fp, $fields, $sep, '"');
}
fclose($fp);
return $nbLignes;
}