diff --git a/library/Metier/Infogreffe/InfogreffeAc.php b/library/Metier/Infogreffe/InfogreffeAc.php index af2148d4..bdda1c1b 100644 --- a/library/Metier/Infogreffe/InfogreffeAc.php +++ b/library/Metier/Infogreffe/InfogreffeAc.php @@ -7,6 +7,8 @@ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Infogreffe.php'; class Metier_Infogreffe_Ac extends Metier_Infogreffe { + const INT = 1000; + /** * Db Adapter * @var Zend_Db_Adapter_Abstract @@ -209,7 +211,7 @@ class Metier_Infogreffe_Ac extends Metier_Infogreffe //Check if filename exist if ( !file_exists($this->config->storage->path . '/' . $filename) ) { - throw new Exception('File not found', 'INT'); + throw new Exception('File not found', self::INT); } } elseif ( file_exists($this->config->storage->path . '/' . $filename) ) { diff --git a/library/Metier/Infogreffe/InfogreffeBi.php b/library/Metier/Infogreffe/InfogreffeBi.php index df5579ed..0097de27 100644 --- a/library/Metier/Infogreffe/InfogreffeBi.php +++ b/library/Metier/Infogreffe/InfogreffeBi.php @@ -7,6 +7,8 @@ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Infogreffe.php'; class Metier_Infogreffe_Bi extends Metier_Infogreffe { + const INT = 1000; + /** * Db Adapter * @var Zend_Db_Adapter_Abstract @@ -127,6 +129,11 @@ class Metier_Infogreffe_Bi extends Metier_Infogreffe $item->ModeDiffusion = ''; } $item->DureeExercice = $row->duree_exercice; + + /** + * Following data are not as expected as the type and other data could change + * Only num depot don't change. + */ $item->SaisieDate = $row->saisie_date; $item->SaisieCode = $row->saisie_code; switch ( $row->saisie_code ) { @@ -220,7 +227,7 @@ class Metier_Infogreffe_Bi extends Metier_Infogreffe //Check if filename exist if ( !file_exists($this->config->storage->path . '/' . $filename) ) { - throw new Exception('File not found', 'INT'); + throw new Exception('File not found', self::INT); } } elseif ( file_exists($this->config->storage->path . '/' . $filename) ) { diff --git a/library/Metier/insee/classMInsee.php b/library/Metier/insee/classMInsee.php index 355c2578..b0edea90 100644 --- a/library/Metier/insee/classMInsee.php +++ b/library/Metier/insee/classMInsee.php @@ -760,6 +760,23 @@ class MInsee return self::$tabDep[$dept]; } + + /** + * Retourne la liste des départements français + * @return array + */ + public function getDepartements() + { + $tabDep = array(); + $departements=$this->iDb->select( + 'insee.departements', + 'numdep, libdep', + 1, false, MYSQL_ASSOC); + foreach ($departements as $dep) { + $tabDep[$dep['numdep']]= $dep['libdep']; + } + return $tabDep; + } /** * Effectif moyen @@ -1658,7 +1675,7 @@ class MInsee } - // + //Vérification du SIREN if ($nbTot==0 && $actif==-1) { require_once 'Metier/sphinx/rechercheFonc.php'; @@ -1682,6 +1699,7 @@ class MInsee } } + //Affichage de la liste des établissements if ( count($listeEtab)>0 ) { foreach ($listeEtab as $etab) { $tel=sprintf('%010d', strtr($etab['tel'],array('-'=>'', '/'=>'','.'=>'',','=>''))); diff --git a/library/framework/common/mysql.new.php b/library/framework/common/mysql.new.php new file mode 100644 index 00000000..8f93c154 --- /dev/null +++ b/library/framework/common/mysql.new.php @@ -0,0 +1,361 @@ + $c->profil->db->metier->adapter, + 'params' => array( + 'host' => $c->profil->db->metier->params->host, + 'username'=> $c->profil->db->metier->params->username, + 'password'=> $c->profil->db->metier->params->password, + 'dbname'=> $database, + 'driver_options' => array( + MYSQLI_INIT_COMMAND => "SET NAMES utf8", + ), + ), + )); + + } else { + $config = new Zend_Config(array( + 'adapter' => 'mysqli', + 'params' => array( + 'host' => $host, + 'username'=> $user, + 'password'=> $password, + 'dbname'=> $database, + 'driver_options' => array( + MYSQLI_INIT_COMMAND => "SET NAMES utf8", + ), + ), + )); + } + + try { + $this->db = Zend_Db::factory($config); + } catch ( Exception $e ) { + file_put_contents('debug.log', $e->getMessage()."\n", FILE_APPEND); + exit; + } + } + + /** + * INSERTION d'un tableau dans une table. + * Les index doivent avoir les mêmes noms que les champs. + * @param string Table + * @param array Valeurs insérer + * @return int Dernière valeur de l'auto-incrément, 1 si pas d'auto-incrément et 0 si erreur + */ + public function insert($table, $toAdd, $debug=false, $low_priority=false) + { + $fields = implode(array_keys($toAdd), '`,`'); + foreach (array_values($toAdd) as $key=>$array_values) + $tmp[$key]=checkaddslashes($array_values); + + $values = "'".implode(array_values($tmp), "','")."'"; # better + $values = str_replace("'NULL'", 'NULL', $values); + + if ($low_priority) + $query = 'INSERT DELAYED INTO `'.$table.'` (`'.$fields.'`) VALUES ('.$values.');'; + else + $query = 'INSERT INTO `'.$table.'` (`'.$fields.'`) VALUES ('.$values.');'; + + if ($debug) $tdeb=microtime_float(); + + try { + $stmt = $this->db->query($query, $debug); + $res = $this->db->lastInsertId(); + if ( $res == 0 ) { + $res = true; + } + } catch(Zend_Db_Exception $e) { + $this->errorCode = $e->getCode(); + $this->errorMsg = $e->getMessage(); + + $res = false; + } + + if ($debug) $this->trace($query, $res, $tdeb); + + return $res; + } + + /** + * + * @param unknown $table + * @param unknown $update + * @param unknown $where + * @param string $debug + * @param number $limit + * @param string $low_priority + * @return resource + */ + public function update($table, $update, $where, $debug=false, $limit=0, $low_priority=false) + { + $fields = array_keys($update); + $values = array_values($update); + $i=0; + if ($low_priority) + $query='UPDATE LOW_PRIORITY `'.$table.'` SET '; + else + $query='UPDATE `'.$table.'` SET '; + while(isset($fields[$i])){ + if($i>0) { $query.=', '; } + $query.=' `'.$fields[$i]."`='".checkaddslashes($values[$i])."'"; + $i++; + } + $query = str_replace("'NULL'", 'NULL', $query); + $query.=' WHERE '.$where; + if ($limit>0) $query.=" LIMIT $limit"; + + if ($debug) $tdeb=microtime_float(); + + try { + $stmt = $this->db->query($query, $debug); + $res = $this->db->lastInsertId(); + if ( $res == 0 ) { + $res = true; + } + } catch(Zend_Db_Exception $e) { + $this->errorCode = $e->getCode(); + $this->errorMsg = $e->getMessage(); + + $res = false; + } + + if ($debug) $this->trace($query, $res, $tdeb); + + return $res; + } + + /** + * + * @param unknown $table + * @param unknown $where + * @param string $debug + * @param string $low_priority + * @return resource + */ + public function delete($table, $where, $debug=false, $low_priority=false) + { + if ($low_priority) + $query='DELETE LOW_PRIORITY QUICK FROM `'.$table.'` WHERE '.$where.' LIMIT 1;'; + else + $query='DELETE FROM `'.$table.'` WHERE '.$where.' LIMIT 1;'; + + if ($debug) $tdeb=microtime_float(); + + try { + $stmt = $this->db->query($query, $debug); + $res = $this->db->lastInsertId(); + if ( $res == 0 ) { + $res = true; + } + } catch(Zend_Db_Exception $e) { + $this->errorCode = $e->getCode(); + $this->errorMsg = $e->getMessage(); + + $res = false; + } + + if ($debug) $this->trace($query, $res, $tdeb); + + return $res; + } + + /** + * + * @param string $table + * @param string $fields + * @param string $where + * @param string $debug + * @param string $assoc + * @param string $huge + * @return boolean|multitype:multitype: |number + */ + public function select($table, $fields, $where, $debug=false, $assoc=MYSQL_BOTH, $huge=false) + { + $query="SELECT $fields FROM $table WHERE $where;"; + + if ($debug) $tdeb=microtime_float(); + + try { + $stmt = $this->db->query($query); + } catch(Zend_Db_Exception $e) { + $this->errorCode = $e->getCode(); + $this->errorMsg = $e->getMessage(); + + $fpErr = fopen(LOG_PATH.'/sqlerror.log','a'); + fwrite($fpErr, date('YmdHis'). ' - '.$query .EOL); + fwrite($fpErr, date('YmdHis'). ' - '.$e->getCode().' - '. $e->getMessage().PHP_EOL); + + return false; + } + + if ( !$huge ) { + switch($assoc) { + case MYSQL_NUM: + $mode = Zend_Db::FETCH_NUM; + break; + case MYSQL_ASSOC: + $mode = Zend_Db::FETCH_ASSOC; + break; + case MYSQL_BOTH: + $mode = Zend_Db::FETCH_BOTH; + break; + } + $tab = $stmt->fetchAll($mode); + if ($debug) $this->trace($query, sizeof($tab), $tdeb); + return $tab; + } else { + $nbRows = $stmt->rowCount(); + if ($debug) $this->trace($query, $nbRows, $tdeb); + return $nbRows; + } + } + + /** + * + * @param string $assoc + * @return multitype: + */ + public function fetch($assoc=MYSQL_BOTH) + { + switch($assoc) { + case MYSQL_NUM: + $mode = Zend_Db::FETCH_NUM; + break; + case MYSQL_ASSOC: + $mode = Zend_Db::FETCH_ASSOC; + break; + case MYSQL_BOTH: + $mode = Zend_Db::FETCH_BOTH; + break; + } + return $this->result->fetch($mode); + } + + /** + * Trace + * @param string $query + * @param string $error + * @param int $tdeb + */ + public function trace($query, $res='', $tdeb = null) + { + + if ( $tdeb === null) { + $duree = substr(''.microtime_float()-$tdeb, 0, 5); + } else { + $duree = 'N/D'; + } + file_put_contents(LOG_PATH . '/mysql_debug.log', date('Y/m/d - H:i:s') ." - ".$this->errorCode.":".$this->errorMsg." - $duree - $query\n", FILE_APPEND); + } + + /** + * Exécute la requête passé en paramètre + */ + public function query($query, $debug=false) + { + try { + $stmt = $this->db->query($query); + $this->result = $stmt; + } catch(Zend_Db_Exception $e) { + $this->errorCode = $e->getCode(); + $this->errorMsg = $e->getMessage(); + + return false; + } + + return $this->result; + } + + /** Retourne le libellé de la dernière erreur **/ + public function getLastErrorMsg() + { + return $this->errorMsg; + } + /** + * Retourne le numéro de la dernière erreur + */ + public function getLastErrorNum() + { + return $this->errorCode; + } + + /** Retourne le libellé et le numéro de la dernière erreur **/ + public function getLastError() + { + return $this->errorMsg.' ('.$this->errorCode.')'; + } + + /** Retourne le nombre de lignes modifiées par la dernière requête **/ + public function getAffectedRows() + { + return $this->result->rowCount(); + } + + /** + * Génère le fichier CSV pour la requete SQL + * + * @param string $query + * @param string $fileCsv + * @return bool + */ + public function exportCSV($query, $fileCsv, $sep=',', $eol=EOL) + { + $i = 0; + $fp = fopen($fileCsv, 'w'); + if (!$fp) return false; + + $res = $this->query($query); + $nbLignes = mysql_num_rows($res); + while ($ligne=$this->fetch(MYSQL_ASSOC)) { + //Header + if ($i==0) { + $nbCols = count($ligne); + $fields = array(); + $header = array(); + foreach ($ligne as $libCol=>$col) { + $header[] = $libCol; + $fields[] = $col; + } + fputcsv($fp, $header, $sep, '"'); + fputcsv($fp, $fields, $sep, '"'); + } + //Content + else { + $fields = array(); + foreach ($ligne as $libCol=>$col) { + $fields[] = $col; + } + fputcsv($fp, $fields, $sep, '"'); + } + $i++; + } + fclose($fp); + return $nbLignes; + } +} +?> \ No newline at end of file diff --git a/library/framework/common/mysql.old.php b/library/framework/common/mysql.old.php new file mode 100644 index 00000000..2d693af7 --- /dev/null +++ b/library/framework/common/mysql.old.php @@ -0,0 +1,228 @@ +host=MYSQL_HOST; + else $this->host=$host; + if ($user=='') $this->user=MYSQL_USER; + else $this->user=$user; + if ($password=='') $this->password=MYSQL_PASS; + else $this->password=$password; + if ($database=='') $this->database=MYSQL_DEFAULT_DB; + else $this->database=$database; + + $this->con_id = mysql_pconnect($this->host, $this->user, $this->password); + if (!($this->con_id === false)) { + if (mysql_select_db($this->database, $this->con_id) === false) { + echo date('Y/m/d - H:i:s') ." - ERREUR ".mysql_errno()." : Connection à la base de données impossible !".EOL; + echo date ('Y/m/d - H:i:s'). mysql_error(); + die(); + } + } + return mysql_query("SET NAMES 'utf8';", $this->con_id); + } + + public function setCharSet($charSet) { + return (mysql_query("SET CHARACTER SET $charSet;", $this->con_id)); + } + + private function setDB() { + return (mysql_query("USE $this->database;", $this->con_id)); + } + + /** INSERTION d'un tableau dans une table. + ** Les index doivent avoir les mêmes noms que les champs. + ** @param string Table + ** @param array Valeurs insérer + ** @return int Dernière valeur de l'auto-incrément, 1 si pas d'auto-incrément et 0 si erreur + **/ +public function insert($table, $toAdd, $debug=false, $low_priority=false){ + $this->setDB(); + $fields = implode(array_keys($toAdd), '`,`'); + foreach (array_values($toAdd) as $key=>$array_values) + $tmp[$key]=checkaddslashes($array_values); + + $values = "'".implode(array_values($tmp), "','")."'"; # better + $values = str_replace("'NULL'", 'NULL', $values); + + if ($low_priority) + $query = 'INSERT DELAYED INTO `'.$table.'` (`'.$fields.'`) VALUES ('.$values.');'; + else + $query = 'INSERT INTO `'.$table.'` (`'.$fields.'`) VALUES ('.$values.');'; + + + if ($debug) $tdeb=microtime_float(); + $res = mysql_query($query, $this->con_id); + if ($res!==false) + { + if (mysql_insert_id()>0) + $res=mysql_insert_id(); + else + $res=true; + } + if ($debug) $this->trace($query, $res, $tdeb); + return $res; + } + +public function update($table, $update, $where, $debug=false, $limit=0, $low_priority=false){ + $this->setDB(); + $fields = array_keys($update); + $values = array_values($update); + $i=0; + if ($low_priority) + $query='UPDATE LOW_PRIORITY `'.$table.'` SET '; + else + $query='UPDATE `'.$table.'` SET '; + while(isset($fields[$i])){ + if($i>0) { $query.=', '; } + $query.=' `'.$fields[$i]."`='".checkaddslashes($values[$i])."'"; + $i++; + } + $query = str_replace("'NULL'", 'NULL', $query); + $query.=' WHERE '.$where; + if ($limit>0) $query.=" LIMIT $limit"; + if ($debug) $tdeb=microtime_float(); + $res=mysql_query($query, $this->con_id); + if ($debug) $this->trace($query, $res, $tdeb); + return $res; + } + +public function delete($table, $where, $debug=false, $low_priority=false) { + $this->setDB(); + if ($low_priority) + $query='DELETE LOW_PRIORITY QUICK FROM `'.$table.'` WHERE '.$where.' LIMIT 1;'; + else + $query='DELETE FROM `'.$table.'` WHERE '.$where.' LIMIT 1;'; + if ($debug) $tdeb=microtime_float(); + $res=mysql_query($query, $this->con_id); + if ($debug) $this->trace($query, $res, $tdeb); + return $res; + } + + public function select($table, $fields, $where, $debug=false, $assoc=MYSQL_BOTH, $huge=false) { + $this->setDB(); + if (mysql_select_db($this->database, $this->con_id) === false) { + echo date('Y/m/d - H:i:s') ." - ERREUR ".mysql_errno()." : Connection à la base de données impossible !".EOL; + echo date ('Y/m/d - H:i:s'). mysql_error(); + die(); + } + $query="SELECT $fields FROM $table WHERE $where;"; + if ($debug) $tdeb=microtime_float(); + $this->result=mysql_query($query, $this->con_id);// or die(mysql_error()); + if (mysql_errno()) { + $fpErr=fopen(LOG_PATH.'/sqlerror.log','a'); + fwrite($fpErr, date('YmdHis'). ' - '.$query .EOL); + fwrite($fpErr, date('YmdHis'). ' - '.mysql_errno() .' - '. mysql_error().EOL); + return false; + } + // echo ; + if (!$huge) { + $tab=array(); + while ($ligne = mysql_fetch_array($this->result, $assoc)) + $tab[]=$ligne; + + if ($debug) $this->trace($query, sizeof($tab), $tdeb); + return $tab; + } else { + $nbRows=mysql_num_rows($this->result); + if ($debug) $this->trace($query, $nbRows, $tdeb); + return $nbRows; + } + } + + public function fetch($assoc=MYSQL_BOTH) { + return mysql_fetch_array($this->result, $assoc); + } + + public function trace($query, $res='', $tdeb=-1) { + if (!$fp=fopen(LOG_PATH.'/mysql_insert.log', 'a')) + return false; + $errnum=mysql_errno($this->con_id); + if ($tdeb>-1) $duree=substr(''.microtime_float()-$tdeb, 0, 5); + else $duree='N/D'; + if (!fwrite($fp, date('Y/m/d - H:i:s') ." - $errnum - $res - $duree - $query\n")) + return false; + if (!fclose($fp)) + return false; + return true; + } + + /** Exécute la requête passé en paramètre **/ + public function query($query, $debug=false){ + $this->setDB(); + $this->result=mysql_query($query, $this->con_id); + return $this->result; + } + + /** Retourne le nombre de records de la dernière requête de sélection ** + public function getNumRows() { + return mysql_num_rows($this->con_id); + } + */ + /** Retourne le libellé de la dernière erreur **/ + public function getLastErrorMsg() { + return mysql_error($this->con_id); + } + /** Retourne le numéro de la dernière erreur **/ + public function getLastErrorNum() { + return mysql_errno($this->con_id); + } + + /** Retourne le libellé et le numéro de la dernière erreur **/ + public function getLastError() { + return mysql_error($this->con_id).' ('.mysql_errno($this->con_id).')'; + } + + /** Retourne le nombre de lignes modifiées par la dernière requête **/ + public function getAffectedRows() { + return mysql_affected_rows($this->con_id); + } + + /** Génère le fichier CSV pour la requete SQL + ** + ** @param string $query + ** @param string $fileCsv + ** @return bool + */ + public function exportCSV($query, $fileCsv, $sep=',', $eol=EOL) { + $i=$c=0; + $fp = fopen($fileCsv, 'w'); + if (!$fp) return false; + + $res=$this->query($query); + $nbLignes=mysql_num_rows($res); + + while ($ligne=$this->fetch(MYSQL_ASSOC)) { + if ($i==0) { + $nbCols=count($ligne); + foreach ($ligne as $libCol=>$col) { + $c++; + if ($c<$nbCols) fwrite($fp, str_replace($sep,' ', $libCol).$sep); + else fwrite($fp, str_replace($sep,' ', $libCol)); + } + fwrite($fp, $eol); + } + $c=0; + foreach ($ligne as $libCol=>$col) { + $c++; + if ($c<$nbCols) fwrite($fp, str_replace($sep,' ', $col).$sep); + else fwrite($fp, str_replace($sep,' ', $col)); + } + fwrite($fp, $eol); + $i++; + } + fclose($fp); + return $nbLignes;//$this->getAffectedRows(); + } + +} +?> \ No newline at end of file diff --git a/library/framework/common/mysql.php b/library/framework/common/mysql.php index 91a23c85..bb6668f4 100644 --- a/library/framework/common/mysql.php +++ b/library/framework/common/mysql.php @@ -9,8 +9,8 @@ class WDB { private $con_id; // Connection ID with MySQL private $result; - public function __construct($database='', $host='', $user='', $password='') { - + public function __construct($database='', $host='', $user='', $password='') + { if ($host=='') $this->host=MYSQL_HOST; else $this->host=$host; if ($user=='') $this->user=MYSQL_USER; @@ -45,8 +45,8 @@ class WDB { ** @param array Valeurs insérer ** @return int Dernière valeur de l'auto-incrément, 1 si pas d'auto-incrément et 0 si erreur **/ -public function insert($table, $toAdd, $debug=false, $low_priority=false){ - $this->setDB(); + public function insert($table, $toAdd, $debug=false, $low_priority=false) + { $fields = implode(array_keys($toAdd), '`,`'); foreach (array_values($toAdd) as $key=>$array_values) $tmp[$key]=checkaddslashes($array_values); @@ -54,11 +54,10 @@ public function insert($table, $toAdd, $debug=false, $low_priority=false){ $values = "'".implode(array_values($tmp), "','")."'"; # better $values = str_replace("'NULL'", 'NULL', $values); - if ($low_priority) - $query = 'INSERT DELAYED INTO `'.$table.'` (`'.$fields.'`) VALUES ('.$values.');'; - else - $query = 'INSERT INTO `'.$table.'` (`'.$fields.'`) VALUES ('.$values.');'; - + if ($low_priority) + $query = 'INSERT DELAYED INTO `'.$table.'` (`'.$fields.'`) VALUES ('.$values.');'; + else + $query = 'INSERT INTO `'.$table.'` (`'.$fields.'`) VALUES ('.$values.');'; if ($debug) $tdeb=microtime_float(); $res = mysql_query($query, $this->con_id); @@ -73,15 +72,15 @@ public function insert($table, $toAdd, $debug=false, $low_priority=false){ return $res; } -public function update($table, $update, $where, $debug=false, $limit=0, $low_priority=false){ - $this->setDB(); + public function update($table, $update, $where, $debug=false, $limit=0, $low_priority=false) + { $fields = array_keys($update); $values = array_values($update); $i=0; - if ($low_priority) - $query='UPDATE LOW_PRIORITY `'.$table.'` SET '; - else - $query='UPDATE `'.$table.'` SET '; + if ($low_priority) + $query='UPDATE LOW_PRIORITY `'.$table.'` SET '; + else + $query='UPDATE `'.$table.'` SET '; while(isset($fields[$i])){ if($i>0) { $query.=', '; } $query.=' `'.$fields[$i]."`='".checkaddslashes($values[$i])."'"; @@ -96,12 +95,12 @@ public function update($table, $update, $where, $debug=false, $limit=0, $low_pri return $res; } -public function delete($table, $where, $debug=false, $low_priority=false) { - $this->setDB(); - if ($low_priority) - $query='DELETE LOW_PRIORITY QUICK FROM `'.$table.'` WHERE '.$where.' LIMIT 1;'; - else - $query='DELETE FROM `'.$table.'` WHERE '.$where.' LIMIT 1;'; + public function delete($table, $where, $debug=false, $low_priority=false) + { + if ($low_priority) + $query='DELETE LOW_PRIORITY QUICK FROM `'.$table.'` WHERE '.$where.' LIMIT 1;'; + else + $query='DELETE FROM `'.$table.'` WHERE '.$where.' LIMIT 1;'; if ($debug) $tdeb=microtime_float(); $res=mysql_query($query, $this->con_id); if ($debug) $this->trace($query, $res, $tdeb); @@ -109,7 +108,6 @@ public function delete($table, $where, $debug=false, $low_priority=false) { } public function select($table, $fields, $where, $debug=false, $assoc=MYSQL_BOTH, $huge=false) { - $this->setDB(); if (mysql_select_db($this->database, $this->con_id) === false) { echo date('Y/m/d - H:i:s') ." - ERREUR ".mysql_errno()." : Connection à la base de données impossible !".EOL; echo date ('Y/m/d - H:i:s'). mysql_error(); @@ -118,12 +116,12 @@ public function delete($table, $where, $debug=false, $low_priority=false) { $query="SELECT $fields FROM $table WHERE $where;"; if ($debug) $tdeb=microtime_float(); $this->result=mysql_query($query, $this->con_id);// or die(mysql_error()); - /*if (mysql_errno()) { + if (mysql_errno()) { $fpErr=fopen(LOG_PATH.'/sqlerror.log','a'); fwrite($fpErr, date('YmdHis'). ' - '.$query .EOL); fwrite($fpErr, date('YmdHis'). ' - '.mysql_errno() .' - '. mysql_error().EOL); return false; - }*/ + } // echo ; if (!$huge) { $tab=array(); @@ -140,25 +138,25 @@ public function delete($table, $where, $debug=false, $low_priority=false) { } public function fetch($assoc=MYSQL_BOTH) { - return mysql_fetch_array($this->result, $assoc); + return mysql_fetch_array($this->result, $assoc); } public function trace($query, $res='', $tdeb=-1) { - /*if (!$fp=fopen(LOG_PATH.'/mysql_insert.log', 'a')) - return false; - $errnum=mysql_errno($this->con_id); - if ($tdeb>-1) $duree=substr(''.microtime_float()-$tdeb, 0, 5); - else $duree='N/D'; - if (!fwrite($fp, date('Y/m/d - H:i:s') ." - $errnum - $res - $duree - $query\n")) - return false; - if (!fclose($fp)) - return false;*/ - return true; + if (!$fp=fopen(LOG_PATH.'/mysql_insert.log', 'a')) + return false; + $errnum=mysql_errno($this->con_id); + if ($tdeb>-1) $duree=substr(''.microtime_float()-$tdeb, 0, 5); + else $duree='N/D'; + if (!fwrite($fp, date('Y/m/d - H:i:s') ." - $errnum - $res - $duree - $query\n")) + return false; + if (!fclose($fp)) + return false; + return true; } /** Exécute la requête passé en paramètre **/ - public function query($query, $debug=false){ - $this->setDB(); + public function query($query, $debug=false) + { $this->result=mysql_query($query, $this->con_id); return $this->result; } @@ -173,17 +171,20 @@ public function delete($table, $where, $debug=false, $low_priority=false) { return mysql_error($this->con_id); } /** Retourne le numéro de la dernière erreur **/ - public function getLastErrorNum() { + public function getLastErrorNum() + { return mysql_errno($this->con_id); } /** Retourne le libellé et le numéro de la dernière erreur **/ - public function getLastError() { + public function getLastError() + { return mysql_error($this->con_id).' ('.mysql_errno($this->con_id).')'; } /** Retourne le nombre de lignes modifiées par la dernière requête **/ - public function getAffectedRows() { + public function getAffectedRows() + { return mysql_affected_rows($this->con_id); } diff --git a/library/framework/fwk.php b/library/framework/fwk.php index 0357c577..fdbcf033 100644 --- a/library/framework/fwk.php +++ b/library/framework/fwk.php @@ -1,4 +1,4 @@ -send(); } catch (Zend_Mail_Transport_Exception $e) { file_put_contents(LOG_PATH.'/sendMailError.log',date('Y-m-d H:i:s')." - ".$e->getMessage().PHP_EOL, FILE_APPEND);