$sql = 'SELECT id, test_nm FROM Test_File LIMIT 3'; $db = new PDO('sqlite:/var/www/db/main.db'); $stmt = $db->prepare($sql); $stmt->execute(); $row = array(1,2,3); echo gettype($row).'</ br>'; // This reports row is an array. foreach ($stmt->fetch(PDO::FETCH_NUM) as $row) { echo 'This should be an array it is a '.gettype($row).'. '; // this reports that row is a string. }This is the result of the query on my server: https://yintercept.com/resources/new.php.
The PDO::fetch() directive on this version of PHP returns a string. The description on PHP.NET says: "PDO::FETCH_NUM: returns an array indexed by column number as returned in your result set, starting at column 0"
I got my compiled version of PHP from lauchpad.net. I guess I am stuck waiting for Ondřej Surý to update this package to PHP 7.0.1 to figure out if this bug is related to something I did or this version.
This failure brings me back the the question: Are objects superior to procedures? Here is an object a production version of PPP 7 causing total failure in the system I am trying to port to PHP 7.
This particular failure took several additional hours to debug because I assumed that the problem was something to do with the path I took through the object. It didn't even dawn on me to actually check the type of the data coming out of PDO::fetch() as the manual said it was an array.
NOTE: A 2008 bug report says the problem is with the database driver and not PHP:
https://bugs.php.net/bug.php?id=44341
No comments:
Post a Comment