php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71185 PDO:fetch(PDO::FETCH_NUM) returns a string
Submitted: 2015-12-21 20:14 UTC Modified: 2015-12-25 11:45 UTC
From: yintercept at msn dot com Assigned: cmb (profile)
Status: Not a bug Package: SQLite (PECL)
PHP Version: 7.0.1 OS: Ubuntu
Private report: No CVE-ID: None
 [2015-12-21 20:14 UTC] yintercept at msn dot com
Description:
------------
The problem is that PDOStatment::fetch(PDO::FETCH_NUM) returns a string instead of an array for the SQLite driver. 

This report is similar to bug report 44341 issued in 2008 .

Bug Report was about MySQL. The conclusion was that the user needed to use a different MySQL driver from ORACLE.

SQLite is not a client server application like ORACLE's MySQL. 

SQLite is simply source code that PHP can embed in its product. SQLite does not have a driver.

Apparently, the root of the problem is that SQLite was designed to the ANSI SQL standard. The standard is String output.

The drivers by ORACLE for MySQL hand PDO parsed data that can be turned into an array.

If my understanding of this situation is true, then PDO has a serious bug. PDO has a dependency on proprietary drivers from third parties like ORACLE (MySQL is a wholly owned division of Oracle Corporation, NYSE ORCL).

From an Open Sourve view point, I would consider the inability to process ANSI standard data while having a dependency on proprietary drivers to be a bigger bug than the simple fact that PDOStatement::fetch() doesn't work for SQLite.

Dismissing this report as a "non-bug" still leaves the problem that SQLite is not a client-server database and does not have a database driver. SQLite just publishes code that PHP can embed in its product, which still throws the ball back in PHP's court.

The following link executes a fetch on my server:

http://yintercept.com/resources/new.php

Test script:
---------------
  $db = new PDO('sqlite:/var/www/db/main.db');
  
  $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>';
  }

Expected result:
----------------
I expect gettype($row) to show an array.

Actual result:
--------------
gettype($row) reports a string that contains only a fraction of the result.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-25 11:45 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2015-12-25 11:45 UTC] cmb@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

In the supplied test script, foreach iterates over the *fields* of
the *first* result row. Use ::fetchAll() instead of ::fetch() for
the desired result.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 11:01:29 2024 UTC