diff --git a/batch/setMinMax.php b/batch/setMinMax.php index 4a23aec7..81c628bd 100644 --- a/batch/setMinMax.php +++ b/batch/setMinMax.php @@ -1,22 +1,88 @@ +#!/usr/bin/php "Aide.", + 'cron' => "Mode automatique", + 'manuel' => "Mode manuel", + ) + ); + $opts->parse(); +} catch (Zend_Console_Getopt_Exception $e) { + echo $e->getUsageMessage(); + exit; +} + +//Usage +if(isset($opts->help)) +{ + echo $opts->getUsageMessage(); + exit; +} + +$dbConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini', 'databases'); +try { + $db = Zend_Db::factory($dbConfig->db); +} catch ( Exception $e ) { + exit ( $e->getMessage() ); +} +//Définition bdd metier +try { + $dbMetier = Zend_Db::factory($dbConfig->jo); +} catch ( Exception $e ) { + exit ( $e->getMessage() ); +} $keys = array( 'nbActio','nbPart', 'teff_entrep', 'teff_etab', 'nbEtab', 'eff_entrep', 'eff_etab', 'capital', 'bilEE', 'bilFL', 'bilFK', 'bilFR', 'bilGF', 'bilGP', 'bilGW', 'bilHD', 'bilHH', 'bilHL', 'bilHM', 'bilHN', 'bilYP' ); -mysql_query('TRUNCATE TABLE minmax', $localhost) or die ('Impossible de vider la table minmax'); -foreach($keys as $key) { - $sql = 'SELECT MIN('.$key.') AS min, MAX('.$key.') AS max FROM etablissements_act'; - $query = mysql_query($sql, $db_230); - $result = mysql_fetch_assoc($query); - $sql = 'INSERT INTO minMax VALUES ("'.$key.'", '.$result['min'].', '.$result['max'].')'; - mysql_query($sql, $localhost) or die(mysql_error($localhost)); - print($key.'-> min:'.$result['min'].' max:'.$result['max']."\n"); + +$sql = 'TRUNCATE TABLE minmax'; +if ( !$db->query($sql) ) { + die ('Impossible de vider la table minmax'); } -print('Terminé'); + +foreach($keys as $key) { + + //Lecture + $sql = 'SELECT MIN('.$key.') AS min, MAX('.$key.') AS max FROM etablissements_act'; + $dbMetier->setFetchMode(Zend_Db::FETCH_ASSOC); + $result = $stmt->fetchAll($sql); + + //Insertion + $data = array( + 'key' => $key, + 'min' => $result['min'], + 'max' => $result['max'], + ); + $db->insert('minmax', $data); + + if ($opts->manuel) print($key.'-> min:'.$result['min'].' max:'.$result['max']."\n"); +} +if ($opts->manuel) print('Terminé');