Personally I wouldn't start off learning PDO by doing try-catch statements as in my opinion will cause more confusion than it is worth. Simply have error reporting turned on to catch the errors.
I personally don't like writing foreach statements that way, I would write it something like the following:
<?php
foreach ($result as $text) {
echo '<blockquote>';
echo '<p>' . htmlspecialchars($text['joketext']) . '</p>';
echo '</blockquote>';
}
?>
as for the pdo I would do something like the following:
$db_options = array(
/* important! use actual prepared statements (default: emulate prepared statements) */
PDO::ATTR_EMULATE_PREPARES => false
/* throw exceptions on errors (default: stay silent) */
, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
/* fetch associative arrays (default: mixed arrays) */
, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
$pdo = new PDO('mysql:host=' . DATABASE_HOST . ';dbname=' . DATABASE_NAME . ';charset=utf8', DATABASE_USERNAME, DATABASE_PASSWORD, $db_options);
$stmt = $pdo->query('SELECT joketext FROM joke');
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
I haven't tested the above out, so I don't know how correct it is.
I would look at this link -> https://phpdelusions.net/pdo as it explains it pretty good in my opinion and I still refer to it from time to time myself.