query("SELECT id FROM posts ORDER BY id DESC LIMIT 1")->fetchAll(); if (!$current_id) $current_id = 0; else $current_id = $current_id[0][0]; for ($i = 0; $i < $total_queries; $i++) { echo "Inserting chunk " . ($i+1) . " of " . $total_queries . "...\n"; $values_clauses = []; $params = []; $posts_tags_sql = []; for ($c = 0; $c < $max_inserts; $c++) { $filesize = rand(2000, 3000); $md5 = md5($time); $width = rand(1500, 2000); $height = rand(1500, 2000); $created_at = date('Y-m-d H:i:s', $time); $rating = $ratings[array_rand($ratings)]; $sample_width = rand(500, 1500); $sample_height = rand(500, 1500); $sample_size = rand(1000, 2000); $index_timestamp = $created_at; $random = rand(100, 9999999999); $values_clauses[] = sprintf($post_values, $filesize, $md5, $width, $height, $created_at, $rating, $sample_width, $sample_height, $sample_size, $index_timestamp, $random); $post_id = $pdo->lastInsertId(); $tag_count = rand(1, $max_tags); $current_id++; foreach (range(1, $tag_count) as $ii) { $posts_tags_sql[] = '(' . $current_id . ', ' . rand(1, 32000) . ')'; } $time++; } $sql = "INSERT INTO posts VALUES "; $sql .= implode(', ', $values_clauses); $pdo->query($sql); $sql = "INSERT INTO posts_tags VALUES " . implode(', ', $posts_tags_sql); $pdo->query($sql); } echo "Done inserting " . $total_posts . " rows.\n";