-
-
Notifications
You must be signed in to change notification settings - Fork 110
Closed
Milestone
Description
Version: v3.0.5
Bug Description
Numeric/Decimal type return as float instead string
Steps To Reproduce
-- mysql
CREATE TABLE `balance` (
`id` int(11) NOT NULL,
`balance` decimal(12,4) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT INTO `balance` (`id`, `balance`) VALUES
(1, 12.1234);
-- postgresql
CREATE TABLE "public"."balance" (
"id" integer NOT NULL,
"balance" numeric(12,4) NOT NULL
) WITH (oids = false);
INSERT INTO "balance" ("id", "balance") VALUES
(1, 12.1234);<?php
$pdo = new PDO('pgsql:host=localhost;dbname=test', 'postgres', 'postgres');
//$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', 'root');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare('SELECT balance FROM balance WHERE id = ?');
$stmt->execute([1]);
var_dump($stmt->fetchColumn());
$db = new Nette\Database\Connection('pgsql:host=localhost;dbname=test', 'postgres', 'postgres');
//$db = new Nette\Database\Connection('mysql:host=localhost;dbname=test', 'root', 'root');
$res = $db->query('SELECT balance FROM balance WHERE id = ?', 1);
var_dump($res->fetchField());after run php code we got
(string) '12.1234'
(float) 12.1234
Expected Behavior
(string) '12.1234'
(string) '12.1234'
Possible Solution
I think float must return only if db field type is float or double
Metadata
Metadata
Assignees
Labels
No labels