PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC] ); $tables = ['user', 'order', 'plan_queue', 'product', 'invoice', 'paylist', 'user_money_log', 'payback', 'invite_up', 'link', 'user_coupon', 'vip_map', 'renewal_quote', 'announcement']; $omitUser = ['ga_token', 'api_token', 'usdt_addr', 'reg_ip', 'remark', 'banned_reason']; $write = static function (array $record): void { echo json_encode($record, JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR), "\n"; }; $counts = $columns = []; foreach ($tables as $table) { $columns[$table] = $connection->query('SHOW COLUMNS FROM `' . $table . '`')->fetchAll(PDO::FETCH_COLUMN); if ($table === 'user') $columns[$table] = array_values(array_diff($columns[$table], $omitUser)); $counts[$table] = (int) $connection->query('SELECT COUNT(*) FROM `' . $table . '`')->fetchColumn(); } $write([ 'kind' => 'header', 'format' => 'fuc-research-snapshot-v1', 'snapshot_utc' => gmdate('c'), 'timezone' => $_ENV['timeZone'], 'database_identity_sha256' => hash('sha256', $_ENV['db_database']), 'counts' => $counts, ]); foreach ($tables as $table) { $fields = implode(',', array_map(static fn ($field) => '`' . $field . '`', $columns[$table])); $order = $table === 'announcement' ? ' ORDER BY sort DESC,date DESC,id DESC' : (in_array('id', $columns[$table], true) ? ' ORDER BY id' : ''); $rows = $connection->query('SELECT ' . $fields . ' FROM `' . $table . '`' . $order); foreach ($rows as $row) $write(['kind' => 'row', 'table' => $table, 'row' => $row]); } $write(['kind' => 'footer', 'counts' => $counts, 'source_business_writes' => 0]); } catch (Throwable $failure) { fwrite(STDERR, get_class($failure) . ' on line ' . $failure->getLine() . "\n"); exit(1); }