reply: setup database to fetch objects
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 21 Oct 2019 06:44:48 +0000 (08:44 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 9 Nov 2019 06:08:13 +0000 (07:08 +0100)
Avoid repetition on each fetch in upcoming usage.

database.inc.php
widget/reply.php

index 6a82507649612a5739bf3fb396062fb1cae2e686..218335814bebf8e993aeb034449d7dc17efae940 100644 (file)
@@ -8,7 +8,10 @@ class DB
 
        function __construct($config, $options = [])
        {
-               $options += [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ];
+               $options += [
+                       PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
+                       PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
+               ];
                $this->dbh = new PDO($config, NULL, NULL, $options);
        }
 
index cfa948715367086f7fd0ce663b7083cf416a75c8..3a16e2c0df1d3d54d1c10a255e9ace49a8edb44c 100644 (file)
@@ -27,7 +27,7 @@ $query = $Db->query('SELECT * FROM comments WHERE page = ? ORDER BY created', [$
 
 print '<ul class="replies">';
 
-while ($row = $query->fetch(PDO::FETCH_OBJ)) {
+while ($row = $query->fetch()) {
        $rowuser = new User("profile/{$row->author}");
        print '<li>';
        printf('<strong>%s</strong> <small class=date>%s</small>',