What is the outcome?

Consider the following table data and PHP code.

What is the outcome?

Table data (table name "users" with primary key "id"):

PHP code (assume the PDO connection is correctly established):

$dsn = ‘mysql:host=localhost;dbname=exam’;

$user= ‘username’;

$pass=’********’;

$pdo = new PD0($dsn, $user, $pass);

try {

$cmd = "INSERT INTO users (id, name, email) VALUES (:id, :name, :email)";

$stmt = $pdo->prepare($cmd);

$stmt->bindValue(‘id’, 1);

$stmt->bindValue(‘name’, ‘anna’);

$stmt->bindValue(’email’, ‘[email protected]’);

$stmt->execute();

echo "Success!";

} catch (PDOException $e) {

echo "Failure!";

throw $e;
A . The INSERT will succeed and the user will see the "Success!" message.
B . The INSERT will fail because of a primary key violation, and the user will see the "Success!" message.
C . The INSERT will fail because of a primary key violation, and the user will see a PDO warning message.
D . The INSERT will fail because of a primary key violation, and the user will see the "Failure!" message.

Answer: B

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments