Zend
200-710 · Question #53
Consider the following table data and PHP code. What is the outcome? Table data (table name "users" with primary key "id"): id name email --- ---- ----- 1 anna [email protected] 2 betty…
The correct answer is D. The value of $result will be '[email protected]'. See the full explanation below for the reasoning.
Databases & SQL
Question
Consider the following table data and PHP code. What is the outcome?
Table data (table name "users" with primary key "id"):
id name email
1 anna [email protected] 2 betty [email protected] 3 clara [email protected] 4 sue [email protected] PHP code (assume the PDO connection is correctly established): $dsn = 'mysql:host=localhost;dbname=exam'; $user = 'username'; $pass = '******'; $pdo = new PDO($dsn, $user, $pass); $cmd = 'SELECT * FROM users WHERE id = :id'; $stmt = $pdo->prepare($cmd); $id = 3; $stmt->bindParam('id', $id); $stmt->execute(); $stmt->bindColumn(3, $result); $srow = $stmt->fetch(PDO::FETCH_BOUND);
1 anna [email protected] 2 betty [email protected] 3 clara [email protected] 4 sue [email protected] PHP code (assume the PDO connection is correctly established): $dsn = 'mysql:host=localhost;dbname=exam'; $user = 'username'; $pass = '******'; $pdo = new PDO($dsn, $user, $pass); $cmd = 'SELECT * FROM users WHERE id = :id'; $stmt = $pdo->prepare($cmd); $id = 3; $stmt->bindParam('id', $id); $stmt->execute(); $stmt->bindColumn(3, $result); $srow = $stmt->fetch(PDO::FETCH_BOUND);
Options
- AThe database will return no rows.
- BThe value of $srow will be an array.
- CThe value of $result will be empty.
- DThe value of $result will be '[email protected]'.
How the community answered
(22 responses)- A5% (1)
- B9% (2)
- C14% (3)
- D73% (16)
Topics
#PDO#bindParam#bindColumn#prepared statements
Community Discussion
No community discussion yet for this question.