Multiple choice technology programming languages

Sample Code Code: INSERT INTO names VALUES ('John') How do you use the DBI module to execute the above SQL statement? Assume $dbh is the return value from DBI->connect.

  1. my $statement = $dbh->execute("INSERT INTO names VALUES ('John')");
  2. my $statement = $dbh->run("INSERT INTO names VALUES ('John')");
  3. my $statement = $dbh->prepare("INSERT INTO names VALUES ('John')"); $statement->execute;
  4. my $statement = $dbh->sql("INSERT INTO names VALUES ('John')"); $statement->execute;
Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The DBI module requires two steps: first prepare the SQL statement with $dbh->prepare(), which returns a statement handle, then execute it with $statement->execute. Options A, B, and D are incorrect because they use non-existent methods (execute, run, sql) directly on the database handle instead of the proper prepare-then-execute pattern.