0
0
PHPprogramming~10 mins

Binding parameters in PHP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to prepare a SQL statement using PDO.

PHP
$stmt = $pdo->[1]("SELECT * FROM users WHERE id = :id");
Drag options to blanks, or click blank then click option'
Aquery
Bprepare
Cexecute
Dfetch
Attempts:
3 left
💡 Hint
Common Mistakes
Using query() instead of prepare() causes errors when binding parameters.
2fill in blank
medium

Complete the code to bind the parameter ':id' as an integer.

PHP
$stmt->bindParam(':id', $id, [1]);
Drag options to blanks, or click blank then click option'
APDO::PARAM_INT
BPDO::PARAM_STR
CPDO::PARAM_BOOL
DPDO::PARAM_NULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using PDO::PARAM_STR for integer parameters causes type mismatch.
3fill in blank
hard

Fix the error in binding a parameter by completing the code.

PHP
$stmt->[1](':name', $name);
Drag options to blanks, or click blank then click option'
Aprepare
BbindValue
Cexecute
DbindParam
Attempts:
3 left
💡 Hint
Common Mistakes
Using bindValue instead of bindParam when variable reference is needed.
4fill in blank
hard

Fill both blanks to bind ':age' as an integer and execute the statement.

PHP
$stmt->[1](':age', $age, [2]);
$stmt->execute();
Drag options to blanks, or click blank then click option'
AbindParam
BbindValue
CPDO::PARAM_INT
DPDO::PARAM_STR
Attempts:
3 left
💡 Hint
Common Mistakes
Using bindValue instead of bindParam when variable reference is required.
Using PDO::PARAM_STR instead of PDO::PARAM_INT for integer values.
5fill in blank
hard

Fill all three blanks to prepare a statement, bind ':email' as string, and execute.

PHP
$stmt = $pdo->[1]("SELECT * FROM users WHERE email = :email");
$stmt->[2](':email', $email, [3]);
$stmt->execute();
Drag options to blanks, or click blank then click option'
Aprepare
BbindParam
CPDO::PARAM_STR
DbindValue
Attempts:
3 left
💡 Hint
Common Mistakes
Using bindValue instead of bindParam when variable reference is needed.
Using PDO::PARAM_INT instead of PDO::PARAM_STR for string parameters.