How to comment tutorial "Displaying Data from MySQL on the Web: an Introduction"

Sorry just wanted comment your tutorial.

The article misses fetchAll method. Instead of manually creating array and loop through cursor there is easiest method. For example

$opt  = array(
                \PDO::ATTR_ERRMODE            => \PDO::ERRMODE_EXCEPTION,
                \PDO::ATTR_EMULATE_PREPARES   => FALSE,
            $dsn = 'mysql:host='.config('database.connections.'.config('database.default').'.host').';dbname='.config('database.connections.'.config('database.default').'.database').';charset=utf8';
            $pdo = new \PDO($dsn, config('database.connections.'.config('database.default').'.username'), config('database.connections.'.config('database.default').'.password'), $opt);
            $stmt = $pdo->query("select id, name from articles ORDER BY id  limit 10");

            $data = $stmt->fetchAll();

Hope it will improve you tutorial

@TomB - a comment for you. smile

Easiest does not always equal best. Allow me to refer you to the free Manual. In reference to fetchall…

Using this method to fetch large result sets will result in a heavy demand on system and possibly network resources. Rather than retrieving all of the data and manipulating it in PHP, consider…

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.