PHP 7.0 v. SQLite3

I've wasted several days debugging this problem and I am considering filing a bug report to PHP about this. The fetch() function in the PDOStatement returns a string instead of an array when used on a SQLite database.

Apparently, this is an ongoing problem as seen in this bug report from 2008. PHP says the problem is with the database driver.

The catch. SQLite is a standards based embedded database. Because it is embedded it has no drivers.

I am claiming that PHP has a dependency injection on the drivers provided by big corporations like ORACLE (MySQL is a division of ORACLE) and Microsoft, and that PDO should be able to handle standards based output from open source embedded programs like SQLite.

Here is a Twitter Poll and a blog post on the issue.


This code shows the error:


  echo '<p>Version: '.phpversion().'</p>';
  $sql = 'SELECT id, program_nm, code_path FROM Code_Viewer WHERE id < 10';

 
  $db = new PDO('sqlite:/var/www/db/main.db');
  // NOTE: These configuration options do not solve the problem.
  // $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
  // $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

  $stmt = $db->prepare($sql);
  $stmt->execute();

  foreach ($stmt->fetch(PDO::FETCH_NUM) as $row) {
    echo '<p>This should be an array, but shows as a '.gettype($row).'.</p>';
  }
 


The Output

This is the output from PHP version "7.0.0-6+deb.sury.org~trusty+1 executed on the server. PDOStatement::fetch() is returning a string when it should an array.

Hopefully, the output will change with the next update (fingers crossed):


Version: 7.0.32-0ubuntu0.16.04.1

This should be an array, but shows as a string

This should be an array, but shows as a string

This should be an array, but shows as a string