0) { $db = new mysqli("localhost", "user", "password", "database"); if($db->connect_errno > 0){ die('Unable to connect to database [' . $db->connect_error . ']'); } for ($i=0; $i<$num_commands; $i++) { $query = "INSERT INTO queue (queue_command) VALUES ('{$commands[$i]}')"; if (!$result = $db->query($query)) { die('There was an error running the query [' . $db->error . ']'); } } mysqli_free_result($result); $db->close(); } ?>