Programming MCQs Feed

📊 PHP
Q. Which PHP function checks if a method exists in a class?
  • (A) method_exists()
  • (B) function_exists()
  • (C) class_has_method()
  • (D) callable_exists()
💬 Discuss
✅ Correct Answer: (A) method_exists()

Explanation: method_exists() checks if a method exists in an object or class.

📊 PHP
Q. Which PHP function checks if a variable is empty?
  • (A) is_null()
  • (B) isset()
  • (C) empty()
  • (D) blank()
💬 Discuss
✅ Correct Answer: (C) empty()

Explanation: empty() checks for empty values including 0, '', null, false.

📊 PHP
Q. Which PHP extension is required to use PDO?
  • (A) mysqli
  • (B) pdo_mysql
  • (C) pdo
  • (D) mysql
💬 Discuss
✅ Correct Answer: (C) pdo

Explanation: The PDO core extension is required; drivers like pdo_mysql are database-specific.

📊 PHP
Q. Which PDO method prepares an SQL statement?
  • (A) query()
  • (B) execute()
  • (C) prepare()
  • (D) bind()
💬 Discuss
✅ Correct Answer: (C) prepare()

Explanation: prepare() prepares a statement for execution.

📊 PHP
Q. Which PDO method executes a prepared statement?
  • (A) run()
  • (B) query()
  • (C) execute()
  • (D) fetch()
💬 Discuss
✅ Correct Answer: (C) execute()

Explanation: execute() runs the prepared statement.

📊 PHP
Q. Which PDO fetch mode returns results as associative arrays?
  • (A) PDO::FETCH_NUM
  • (B) PDO::FETCH_OBJ
  • (C) PDO::FETCH_ASSOC
  • (D) PDO::FETCH_BOTH
💬 Discuss
✅ Correct Answer: (C) PDO::FETCH_ASSOC

Explanation: FETCH_ASSOC returns only associative array results.

📊 PHP
Q. Which PDO fetch mode returns results as objects?
  • (A) PDO::FETCH_OBJ
  • (B) PDO::FETCH_CLASS
  • (C) PDO::FETCH_ASSOC
  • (D) PDO::FETCH_LAZY
💬 Discuss
✅ Correct Answer: (A) PDO::FETCH_OBJ

Explanation: FETCH_OBJ maps rows to anonymous objects.

📊 PHP
Q. Which PDO method starts a database transaction?
  • (A) startTransaction()
  • (B) begin()
  • (C) beginTransaction()
  • (D) transaction()
💬 Discuss
✅ Correct Answer: (C) beginTransaction()

Explanation: beginTransaction() starts a DB transaction.

📊 PHP
Q. Which PDO method commits a transaction?
  • (A) save()
  • (B) commit()
  • (C) end()
  • (D) complete()
💬 Discuss
✅ Correct Answer: (B) commit()

Explanation: commit() saves changes permanently.

📊 PHP
Q. Which PDO method rolls back a transaction?
  • (A) rollback()
  • (B) undo()
  • (C) cancel()
  • (D) reverse()
💬 Discuss
✅ Correct Answer: (A) rollback()

Explanation: rollback() reverts transaction changes.