php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45484 PDOStatment set datatype to string
Submitted: 2008-07-11 11:03 UTC Modified: 2016-03-08 01:32 UTC
From: cbidon007 at hotmail dot com Assigned:
Status: No Feedback Package: PDO OCI
PHP Version: 5.2.6 OS: windows xp
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cbidon007 at hotmail dot com
New email:
PHP Version: OS:

 

 [2008-07-11 11:03 UTC] cbidon007 at hotmail dot com
Description:
------------
Hy,

I use an oracle database and my locale setting for the decimal point is ",".
When I run a SELECT query with a float datatype column, the result is a string datatype value and the decimal separator is ','.
And PHP don't recognize this as a number.

Why oracle column datatypes are not kept?


Reproduce code:
---------------
$oPDOStmt = $oConn->query("SELECT 12.34 AS NB FROM DUAL");
$arrResult = $oPDOStmt->fetch(PDO::FETCH_ASSOC);
print_r($arrResult);
print gettype($arrResult["NB"]);

Expected result:
----------------
Array
(
    [NB] => 12.34
)

Actual result:
--------------
Array
(
    [NB] => 12,34
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-05 08:50 UTC] uw@php.net
The string conversion is not a bug in the driver. Its how PDO has been designed. FETCH:ASSOC will always perform a string conversion regardless of the driver. Use bindColumn():

$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
$stmt = $db->query("SELECT 1");
$stmt->bindColumn(1, $value, PDO::PARAM_INT);
$stmt->fetch(PDO::FETCH_BOUND)

Not respected locale setting might be a bug. Check again using bindColumn(). 

 [2008-08-26 12:46 UTC] cbidon007 at hotmail dot com
The problem is still here.
I have a french system with the decimal separator ","

I would like to get a float number (e.g. 12.34). When is use bindColumn(), I get 12 if I use the PDO::PARAM_INT or 12,34 if I use the PDO::PARAM_STR.

Is it possible to retreive a float number with PDO in this condition ?
 [2009-04-25 15:09 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-05-03 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2016-03-08 01:32 UTC] sixd@php.net
-Package: PDO related +Package: PDO OCI
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC