Skip to content

Instantly share code, notes, and snippets.

@ety001
Created May 7, 2018 08:24
Show Gist options
  • Select an option

  • Save ety001/2538bb2a6e355f036d256336c433a362 to your computer and use it in GitHub Desktop.

Select an option

Save ety001/2538bb2a6e355f036d256336c433a362 to your computer and use it in GitHub Desktop.
去掉冗余数据
<?php
$servername = "";
$username = "";
$password = "";
$conn = new PDO("mysql:host=$servername;dbname=steemdb", $username, $password);
$i = 2508;
$end = 3263402; // 3263402
$step = 100;
while ($i <= $end) {
$tmp_end = $i + $step;
$sql = "select block_num, block_info from blocks where block_num >= {$i} and block_num <= {$tmp_end}";
$sth = $conn->prepare($sql);
$sth->execute();
$res = $sth->fetchAll();
var_dump($i, $tmp_end, $res);
echo "\n";
$update_sql = "update blocks set block_info = case block_num ";
$tmp_block_num = [];
foreach($res as $k => $v) {
$tmp_info = $v['block_info'];
$tmp_info = json_decode($tmp_info, true);
if (isset($tmp_info['previous'])) {
unset($tmp_info['previous']);
}
if (isset($tmp_info['timestamp'])) {
unset($tmp_info['timestamp']);
}
if (isset($tmp_info['block_id'])) {
unset($tmp_info['block_id']);
}
if (isset($tmp_info['block_num'])) {
unset($tmp_info['block_num']);
}
$tmp_info = json_encode($tmp_info);
$update_sql .= " when {$v['block_num']} then '{$tmp_info}' ";
array_push($tmp_block_num, $v['block_num']);
}
$tmp_block_num_str = implode(',', $tmp_block_num);
$update_sql .= " end where block_num in ({$tmp_block_num_str})";
echo $update_sql."\n\n";
$conn->exec($update_sql);
$i = $tmp_end + 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment