You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
3.1 KiB
PHTML
105 lines
3.1 KiB
PHTML
2 years ago
|
<?php
|
||
|
|
||
|
include('config.henan.inc.php');
|
||
|
|
||
|
$elinewatch = array('database' => 'elinewatch_132', 'dbuser' => 'exp', 'password' => 'exp@123', 'host' => '192.168.111.12');
|
||
|
|
||
|
$terms = array();
|
||
|
$db = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['database'], $config['dbuser'], $config['password'], [
|
||
|
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
|
||
|
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'"
|
||
|
]);
|
||
|
|
||
|
$db2 = new PDO('mysql:host=' . $elinewatch['host'] . ';dbname=' . $elinewatch['database'], $elinewatch['dbuser'], $elinewatch['password'], [
|
||
|
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
|
||
|
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'"
|
||
|
]);
|
||
|
|
||
|
|
||
|
$sql = "select `id`, cmdid from terminals";
|
||
|
foreach ($db->query($sql) as $row)
|
||
|
{
|
||
|
$terms[$row['cmdid']] = $row['id'];
|
||
|
}
|
||
|
|
||
|
$cnt = 0;
|
||
|
$sql = 'SELECT COUNT(*) as cnt FROM t_news_conduct_line_pull';
|
||
|
foreach ($db2->query($sql) as $row)
|
||
|
{
|
||
|
$cnt = $row['cnt'];
|
||
|
}
|
||
|
|
||
|
$minid = 0;
|
||
|
$content = @file_get_contents('./data/weather.txt');
|
||
|
if (!empty($content))
|
||
|
{
|
||
|
$minid = intval($content);
|
||
|
}
|
||
|
|
||
|
$sql = "SELECT `id`,UNIX_TIMESTAMP(ext13) as update_time,ext12 as cmdid,tag1 as air_temperature,tag2 as humidity,tag3 as standard_wind_speed,tag4 as wind_direction,tag5 as precipitation,ext14 as air_pressure," .
|
||
|
"ext15 as radiation_Intensity,ext16 as avg_wind_speed_1min,ext17 as avg_wind_dir_1min,ext18 as avg_wind_speed_10min,ext19 as avg_wind_dir_10min,ext20 as max_wind_speed FROM `t_news_weather` WHERE `id`>:minid ORDER BY `id` LIMIT 10000";
|
||
|
|
||
|
$sql2 = "INSERT INTO weathers(term_id,update_time,air_temperature,humidity,standard_wind_speed,wind_direction,precipitation,air_pressure,radiation_Intensity,avg_wind_speed_1min,avg_wind_dir_1min,avg_wind_speed_10min,avg_wind_dir_10min,max_wind_speed) " .
|
||
|
" VALUES(:term_id,:update_time,:air_temperature,:humidity,:standard_wind_speed,:wind_direction,:precipitation,:air_pressure,:radiation_Intensity,:avg_wind_speed_1min,:avg_wind_dir_1min,:avg_wind_speed_10min,:avg_wind_dir_10min,:max_wind_speed)";
|
||
|
|
||
|
$stmt = $db2->prepare($sql);
|
||
|
$stmt2 = $db->prepare($sql2);
|
||
|
|
||
|
$idx = 1;
|
||
|
while (1)
|
||
|
{
|
||
|
$res = $stmt->execute(array(':minid' => $minid));
|
||
|
if (!$res)
|
||
|
{
|
||
|
echo $sql;
|
||
|
exit();
|
||
|
}
|
||
|
|
||
|
$rows = $stmt->fetchAll();
|
||
|
if (count($rows) == 0)
|
||
|
{
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
$db->beginTransaction();
|
||
|
foreach ($rows as $row)
|
||
|
{
|
||
|
$values = array();
|
||
|
|
||
|
$minid = $row['id'];
|
||
|
$values[':term_id'] = $terms[$row['cmdid']];
|
||
|
|
||
|
unset($row['cmdid']);
|
||
|
unset($row['id']);
|
||
|
|
||
|
foreach ($row as $key => $val)
|
||
|
{
|
||
|
$values[':' . $key] = $val;
|
||
|
}
|
||
|
|
||
|
$res = $stmt2->execute($values);
|
||
|
if ($res == true)
|
||
|
{
|
||
|
// print_r($res);
|
||
|
echo $idx . '/' . $cnt . " id:" . $minid . "\r\n";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// print_r($res);
|
||
|
// print_r($stmt->errorInfo());
|
||
|
// print_r($values);
|
||
|
// exit;
|
||
|
}
|
||
|
|
||
|
$idx++;
|
||
|
}
|
||
|
$db->commit();
|
||
|
|
||
|
$stmt->closeCursor();
|
||
|
|
||
|
}
|
||
|
|
||
|
file_put_contents('./data/weather.txt', $minid);
|
||
|
|
||
|
|