Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/19/2020 in all areas

  1. 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.
    1 point
  2. Telling us what the problem is goes a long way towards getting it resolved.
    0 points
This leaderboard is set to New York/GMT-04:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.