How can I prepare a database statement and execute it many times with different input?
Prepared statements can be created after changing the statement class to PDOStatement. This technique is described in How to execute stored procedures in drupal?

// Get the Drupal database connection and change the statement class to PDOStatement.
// Save the current class for cleanup later.
$conn = Database::getConnection();
$saved_class = $conn-&gt;getAttribute(PDO::ATTR_STATEMENT_CLASS);
$conn-&gt;setAttribute(PDO::ATTR_STATEMENT_CLASS, array('PDOStatement'));

// code from the question:
$check = $conn-&gt;prepare('SELECT COUNT(*) FROM other_tablename WHERE colname = :value');
$insert = $conn-&gt;prepare('INSERT INTO tablename (colname) VALUES (:value)');
foreach ($my_many_items as $item) {
  $check-&gt;execute(array(':value' =&gt; $item));
  if ($check-&gt;fetchColumn() &lt; 1) {
    $insert-&gt;execute(array(':value' =&gt; $item));
  }
}

// Revert the connection to its previous statement class.
$conn-&gt;setAttribute(PDO::ATTR_STATEMENT_CLASS, $saved_class);