When using PDO, which method is used to prepare a statement for execution?

  • prepare()
  • execute()
  • query()
  • bindParam()
The prepare() method in PDO is used to prepare an SQL statement for execution. It's typically used with placeholders to prevent SQL injection and to improve query performance by reusing the prepared statement with different parameter values.

The ________ function in PHP can be used to regenerate a session ID.

  • session_regenerate_cookie
  • session_regenerate_id
  • session_reset_id
  • session_destroy
The correct option is session_regenerate_id. It regenerates the session ID and helps enhance session security.

The PHP function used to split an array into chunks of new arrays with specified size is ________.

  • array_chunk
  • array_split
  • array_divide
  • array_segment
The array_chunk function in PHP divides an array into chunks of specified size. It's useful for tasks like pagination, where you split data into manageable portions.

To get the ASCII value of the first character of a string in PHP, you would use the ________ function.

  • ord()
  • ascii()
  • charCode()
  • getASCII()
The 'ord()' function in PHP is used to obtain the ASCII value of the first character of a string. It's handy for character-level operations.

Consider a scenario where you are designing a survey form where questions can be dynamically added by the admin. How would you design the form fields to ensure all data is captured correctly in PHP?

  • Use an array of form fields
  • Use session variables
  • Use cookies
  • Use hidden fields
To ensure that all dynamically added questions are captured correctly in PHP, it's advisable to use an array of form fields. Each dynamically added question can have its own field within the array.

In a SQL JOIN operation, which keyword is used to return all records when there is a match in one of the tables?

  • INNER JOIN
  • RIGHT JOIN
  • LEFT JOIN
  • FULL JOIN
In a SQL JOIN operation, the LEFT JOIN keyword is used to return all records from the left (or first) table, and the matched records from the right (or second) table. If there's no match in the right table, NULL values are returned. This is useful when you want to retrieve all records from one table and only matching records from another. It's commonly used to create inclusive result sets.

The PHP function ________ can be used to verify if a given password matches a hashed password.

  • password_verify()
  • hash_compare()
  • verify_password()
  • compare_passwords()
The password_verify() function is specifically designed for verifying a password against its hashed value, enhancing security in user authentication processes. This is a key concept in web security.

To ensure a file resource is closed and memory is freed up, you should use the ________ function in PHP.

  • close_file()
  • flush()
  • fclose()
  • release_memory()
The fclose() function in PHP is used to close an open file resource. This ensures that the file is properly closed, and associated memory is released.

When validating user credentials, it's essential to use a function that compares hashed values in a way that is:

  • Constant Time (O(1))
  • Linear Time (O(n))
  • Exponential Time (O(2^n))
  • Logarithmic Time (O(log n))
The key to secure credential validation is to use a constant-time comparison to avoid timing attacks. A constant-time comparison ensures that the function takes the same amount of time regardless of whether the comparison succeeds or fails. This makes it harder for attackers to infer information based on timing differences.

For how long does a session variable persist by default in PHP?

  • Until the browser is closed
  • Until the server restarts
  • For 24 hours
  • Until the session ends
By default, session variables in PHP persist until the session ends. This typically happens when the user closes the browser or remains inactive for a set period, often 24 minutes.