Simule una situación de falla de recuperación de PDO

Conforme a los documentos php, el método PDOir a buscar() devuelve el valorFALSE ambos cuando no se encuentran registrosY en caso de falla (por ejemplo, cuando algo sale mal con respecto al acceso a la base de datos).

Supongamos que configuro el sistema de informe de errores de PHP para lanzar excepciones en caso de falla:

PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION

Necesito un caso, una situación en la que elfetch() El método arrojará una excepción. ¿Por qué? Porque quiero comprobar, para estar 100% seguro de quefetch() lanza una excepción al fracaso, y no solo regresaFALSE en caso de fracaso

Si ese fuera el caso, entonces consideraríaFALSE devuelto porfetch() como resultado de no encontrar ningún registro en la tabla db.

Entonces, mi pregunta sería: ¿Conoces una forma de simular una situación de falla para elfetch() ¿método?

Gracias.

PD: La respuesta a mi pregunta me ayudará a encontrar la respuesta para mi otra pregunta:PHP PDO fetch devuelve FALSE cuando no se encuentran registros Y en caso de falla

Editar 1:

También preparé un ejemplo para mostrar cómo manejo las excepciones. Se trata de una simple consulta SQL, obtener un usuario de unusers mesa:

<?php

// Activate error reporting.
error_reporting(E_ALL);
ini_set('display_errors', 1);

try {

    // Create a PDO instance as db connection to a MySQL db.
    $connection = new PDO(
            'mysql:host=localhost;port=3306;dbname=mydb;charset=utf8'
            , 'myuser'
            , 'mypass'
            , array(
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_EMULATE_PREPARES => FALSE,
        PDO::ATTR_PERSISTENT => TRUE
            )
    );

    // Define the sql statement.
    $sql = 'SELECT * FROM users WHERE name = :name';

    /*
     * Prepare and validate the sql statement.
     * 
     * --------------------------------------------------------------------------------
     * If the database server cannot successfully prepare the statement, PDO::prepare() 
     * returns FALSE or emits PDOException (depending on error handling settings).
     * --------------------------------------------------------------------------------
     */
    $statement = $connection->prepare($sql);

    if (!$statement) {
        throw new UnexpectedValueException('The sql statement could not be prepared!');
    }

    // Bind the input parameter to the prepared statement.
    $bound = $statement->bindValue(':name', 'Sarah', PDO::PARAM_STR);

    // Validate the binding of the input parameter.
    if (!$bound) {
        throw new UnexpectedValueException('An input parameter can not be bound!');
    }

    /*
     * Execute the prepared statement.
     * 
     * ------------------------------------------------------------------
     * PDOStatement::execute returns TRUE on success or FALSE on failure.
     * ------------------------------------------------------------------
     */
    $executed = $statement->execute();

    if (!$executed) {
        throw new UnexpectedValueException('The prepared statement can not be executed!');
    }

    /*
     * Fetch and validate the result set.
     * 
     * =========================================================
     * Note:
     * =========================================================
     * PDOStatement::fetch returns FALSE not only on failure,
     * but ALSO when no record is found!
     * 
     * Instead, PDOStatement::fetchAll returns FALSE on failure,
     * but an empty array if no record is found. This is the
     * natural, desired behaviour.
     * =========================================================
     */
    $resultset = $statement->fetch(PDO::FETCH_ASSOC);

    if ($resultset === FALSE) {
        throw new UnexpectedValueException('Fetching data failed!');
    }

    // Display the result set.
    var_dump($resultset);
    echo '<pre>' . print_r($resultset, TRUE) . '</pre>';

    // Close connection.
    $connection = NULL;
} catch (PDOException $exc) {
    echo '<pre>' . print_r($exc, TRUE) . '</pre>';
    exit();
} catch (Exception $exc) {
    echo '<pre>' . print_r($exc, TRUE) . '</pre>';
    exit();
}

Usé la siguiente sintaxis de crear tabla:

DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=124 DEFAULT CHARSET=utf8;

y los siguientes valores de la tabla:

INSERT INTO `users` (`id`, `name`)
VALUES
    (1,'Sarah'),
    (2,'John');

Entonces, la tabla se ve así:

id  name
--------
1   Sarah
2   John

Respuestas a la pregunta(3)

Su respuesta a la pregunta