|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-04-08 19:40 UTC] dharman@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: nikic
[2021-04-08 19:40 UTC] dharman@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 03:00:02 2025 UTC |
Description: ------------ When fetching data from a MySQL database, the type of the field is ignored and the column data is always returned as a string. Constrast this with the PostgreSQL driver which does return the type of the field. The test script below demonstrates an integer field is retruned as a string for MySQL but properly returned as an int for PostgreSQL. Test script: --------------- <?php $db = new PDO('pgsql:dbname=test', 'postgres'); $db->exec('DROP TABLE IF EXISTS test_table'); $db->exec('CREATE TABLE test_table (field integer)'); $db->exec('INSERT INTO test_table VALUES (5)'); $stmt = $db->query('SELECT * FROM test_table'); var_dump($stmt->fetch()); $db = new PDO('mysql:dbname=test', 'postgres'); $db->exec('DROP TABLE IF EXISTS test_table'); $db->exec('CREATE TABLE test_table (field integer)'); $db->exec('INSERT INTO test_table VALUES (5)'); $stmt = $db->query('SELECT * FROM test_table'); var_dump($stmt->fetch()); Expected result: ---------------- array(2) { 'field' => int(5) [0] => int(5) } array(2) { 'field' => int(5) [0] => int(5) } Actual result: -------------- array(2) { 'field' => int(5) [0] => int(5) } array(2) { 'field' => string(1) "5" [0] => string(1) "5" }