Date Field Issue in Union query when setting PDO::ATTR_EMULATE_PREPARES false

Viewed 94

When executing a PDO prepared query with emulate_prepares set to false, with a date column and a union statement the date field is returned malformed (eg. expected result: 2019-10-02, actual result: \xe3\x07\n\x02)

Query runs as expected with emulate_prepares set to true.

PHP Version: 7.2.19-0ubuntu0.18.04.2 DB Version: 10.1.41-MariaDB-0ubuintu0.18.04.1

I'm providing a very simple query below to demonstrate the issue but normally this query runs against an actual table with real data. The same issue manifests in both cases.

<?php

$options= [
PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_BOUND,
PDO::ATTR_EMULATE_PREPARES => FALSE
];

$db = new PDO('mysql:host=localhost;dbnam=db;charset=utf8', user, password, $options);

$stmt = $db->prepare("
SELECT CURRENT_DATE AS 'date' FROM DUAL
UNION ALL
SELECT CURRENT_DATE FROM DUAL");

$stmt->bindColumn("date", $date);

$stmt->execute();

while($stmt->fetch())
{
print $date."<br>";
}
Results for PDO:ATTR_EMULATE_PREPARES = FALSE
�
�

Results for PDO:ATTR_EMULATE_PREPARES = TRUE
2019-10-02
2019-10-02

The date is returned correctly if I remove the Union.

1 Answers

Thanks @Your Common Sense for checking on your end, upgrading resolved the issue. I'm on version 10.4.8-MariaDB now and the issue is resolved.

I ran apt-get to make sure I was on the latest version of MariaDB but forgot to check what version Ubuntu 18.04 limited MaraiDB to on the base repos. I should have applied my own common sense.

Related