php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76408 no result if field in where clause of SQL-statement is float
Submitted: 2018-06-02 22:10 UTC Modified: 2018-06-02 22:13 UTC
From: michael dot gautschi at gmail dot com Assigned:
Status: Not a bug Package: PDO related
PHP Version: 7.2.6 OS: Windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: michael dot gautschi at gmail dot com
New email:
PHP Version: OS:

 

 [2018-06-02 22:10 UTC] michael dot gautschi at gmail dot com
Description:
------------
If the type of the field is "float" a query with a parameter will not return any result and if the same field has the type "decimal" a result is returned.



Test script:
---------------
Let's create two tables:

CREATE TABLE `weightd` (
  `idweight` int(11) NOT NULL,
  `weightkg` decimal(10,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
INSERT INTO `weightd` (`idweight`, `weightkg`) VALUES (1, '77.90');

CREATE TABLE `weightf` (
  `idweight` int(11) NOT NULL,
  `weightkg` float(10,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
INSERT INTO `weightf` (`idweight`, `weightkg`) VALUES (1, '77.90');

------
The script:

<?php


$db = new PDO('mysql:host=localhost;dbname=test', 'user', 'pass');
$s = $db->prepare('select * from `weightd` where `weightkg` = :p0');
$s->execute(array(':p0' => '77.9'));
$r = $s->fetchAll();
var_dump($r);

$db = new PDO('mysql:host=localhost;dbname=test', 'user', 'pass');
$s = $db->prepare('select * from `weightf` where `weightkg` = :p0');
$s->execute(array(':p0' => '77.9'));
$r = $s->fetchAll();
var_dump($r);

Expected result:
----------------
Two times the following output:

array (size=1)
  0 => 
    array (size=4)
      'idweight' => string '1' (length=1)
      0 => string '1' (length=1)
      'weightkg' => string '77.90' (length=5)
      1 => string '77.90' (length=5)

Actual result:
--------------
array (size=1)
  0 => 
    array (size=4)
      'idweight' => string '1' (length=1)
      0 => string '1' (length=1)
      'weightkg' => string '77.90' (length=5)
      1 => string '77.90' (length=5)

array (size=0)
  empty

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-02 22:13 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 18:01:31 2024 UTC