Batch au couleur de zend
This commit is contained in:
parent
db04d8c77e
commit
41a7d74bfd
@ -1,22 +1,88 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
$db_230 = mysql_connect('192.168.78.230', 'sphinx', 'indexer');
|
||||
mysql_select_db('jo', $db_230);
|
||||
// Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
|
||||
|
||||
$localhost = mysql_connect('127.0.0.1', 'root', '');
|
||||
mysql_select_db('sdciblage', $localhost);
|
||||
// Define application environment
|
||||
define('APPLICATION_ENV', 'production');
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
)));
|
||||
|
||||
/** Zend_Application */
|
||||
require_once 'Zend/Application.php';
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
);
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
//Options
|
||||
array(
|
||||
'help|?' => "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é');
|
||||
|
Loading…
Reference in New Issue
Block a user