In PDO, the placeholders used in prepared statements can be either named or ________.
- Indexed
- Positional
- Indexed or Positional
- Named
In PDO, placeholders in prepared statements can be either named (e.g., :name) or positional (e.g., ?). Both are valid ways to bind values.
Which PHP function is used to set a cookie?
- setCookie()
- createCookie()
- sendCookie()
- cookie()
The correct function is setCookie(). It is used in PHP to set cookies on the client's browser. Cookies are often used for tracking user preferences or maintaining session data.
The PHP function that merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one is ________.
- array_merge
- array_combine
- array_push
- array_merge_recursive
The correct function is 'array_merge.' This function takes multiple arrays and combines them, appending the values of one array to the end of the previous one.
What is the main difference between the strcmp() and strcasecmp() functions in PHP?
- strcmp() compares case
- strcmp() is for binary
- strcmp() returns 0 on
- strcmp() is for
The main difference is that strcmp() is case-sensitive and returns 0 when two strings are equal, while strcasecmp() is case-insensitive and still returns 0 on equality.
Why is it recommended to use prepared statements in PHP when interacting with a database?
- To improve code readability.
- To prevent SQL injection attacks.
- To reduce the need for database indexes.
- To enhance database schema design.
Prepared statements prevent SQL injection attacks by separating SQL code from user input, making it safer to execute database queries.
When an error is not caught in PHP, it results in a ________ error.
- Fatal
- Syntax
- Logical
- Run-time
When an error is not caught in PHP, it results in a 'Fatal' error, which typically terminates script execution. Fatal errors often include issues like calling an undefined function or division by zero.
Which of the following is NOT a recommended approach to prevent SQL injection attacks in PHP?
- Using Prepared Statements
- Validating and Sanitizing User Input
- Escaping User Input with mysqli_real_escape_string()
- Disabling Error Reporting
Validating and sanitizing user input is an essential step in preventing SQL injection attacks. Therefore, it is not recommended to avoid this step. Other options, like using prepared statements and escaping user input, are recommended practices to prevent SQL injection in PHP. Disabling error reporting, while helpful, is not the primary method for prevention.
When you don't want to handle an exception and want it to be handled by a parent catch block, you can use the ________ keyword.
- rethrow
- propagate
- throwup
- throw
The throw keyword is used to rethrow an exception that you don't want to handle in the current catch block, allowing it to be caught by a parent catch block.
To append one or more elements to the end of an array, the ________ function is used.
- array_push
- array_merge
- array_append
- array_combine
The array_push function is used to append one or more elements to the end of an array in PHP. It's a way to add elements to an existing array.
Imagine you're building a multi-step form in PHP. At the third step, you need to access data from the first step without re-submitting the form. Which PHP feature would allow you to do this?
- Sessions
- Cookies
- Hidden Fields
- Server Variables
Using Hidden Fields allows data from a previous step to be included in the form without resubmitting, enabling continuity in a multi-step process.