9 quizzes found.

Which of the following is not a valid PDO DSN?

  1. All of the above are valid
  2. mysql:unix_socket=/tmp/mysql.sock;dbname=testdb
  3. oci:dbname=//localhost:1521/mydb
  4. mysql:host=localhost;port=3307;dbname=testdb
  5. sqlite2:/opt/databases/mydb.sq2

Choose 1 answers

When connecting to a database using PDO, what must be done to ensure that database credentials are not compromised if the connection were to fail?

  1. wrap the PDO DSN in a try/catch block to catch any connection exception
  2. Use constants in the PDO DSN
  3. Place the login credentials in the php.ini file
  4. Disable E_STRICT and E_NOTICE error reporting levels

Choose 1 answers

Consider the following script; What lines of code need to go into the missing places above in order for this script to function properly and insert the data into the database safely?

<?phptry { $dbh = new PDO("sqlite::memory:");} catch(PDOException $e) { print $e->getMessage();}$dbh->query("CREATE TABLE foo(id INT)");$stmt = $dbh->prepare("INSERT INTO foo VALUES(:value)");$value = null;$data = array(1,2,3,4,5);$stmt->bindParam(":value", $value);/* ?????? */try { foreach($data as $value) { /* ????? */ }} catch(PDOException $e) { /* ??????? */}/* ?????? */?>
  1. $dbh->commit();
  2. $stmt->execute();
  3. $dbh->rollback();
  4. $dbh->query($stmt);

Choose 3 answers

Implementing your own PDO class requires which steps from the list below?

  1. Extending the PDOStatement Class
  2. Set the PDO::ATTR_STATEMENT_CLASS parameter
  3. Call the PDO::setStatementClass() method
  4. Extend the PDO class
  5. Set the PDO::ATTR_USE_CLASS paramater

Choose 3 answers

Which of the following methods are used to fetch data from a PDO Statement?

  1. fetchColumn()
  2. fetchObject()
  3. fetch()
  4. fetchClass()
  5. fetchRow()

Choose 3 answers