Discussion:
[JIRA] Created: (MYO-100) MySQL datetime values do not bind correctly to PHP
Robert Hodges (JIRA)
2009-07-08 21:46:46 UTC
Permalink
MySQL datetime values do not bind correctly to PHP
--------------------------------------------------

Key: MYO-100
URL: https://forge.continuent.org/jira/browse/MYO-100
Project: Tungsten Connector
Type: Bug

Components: MySQL protocol
Environment: MySQL 5.0.x, PHP 5.1
Reporter: Robert Hodges
Assigned to: Gilles Rayrat
Priority: Blocker
Fix For: 0.6.8


The Tungsten Connector in some cases does not bind datetime and timestamp values correctly to PHP 5.1. The time value is truncated. Here's a script to reproduce:

<?php
// Initialize a mysqli object to $mysqli
$mysqli->query('drop database if exists datetimetest');
$mysqli->query('create database datetimetest');
$mysqli->query('create table datetimetest.datetimes (
`recordID` int not null auto_increment primary key,
`startTime` datetime null,
`endTime` datetime null
)');
$mysqli->query('insert into datetimetest.datetimes set startTime = now(), endTime = now()');
$sql = 'select * from datetimetest.datetimes';
echo '<h1>Query</h1>';
$result = $mysqli->query($sql);
while ($row = $result->fetch_array(MYSQLI_NUM)) {
var_export($row);
echo '<br><br>';
}

echo '<h1>Prepare</h1>';
$stmt = $mysqli->prepare($sql);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result(&$startTime, &$endTime, &$creationDate);
$values = array(&$startTime, &$endTime, &$creationDate);

$retval = $stmt->fetch();
while ($retval !== null && $retval !== false) {
var_export($values);
echo '<br><br>';
$retval = $stmt->fetch();
}
$mysqli->query('drop database datetimetest');
?>

Output:
Query
array ( 0 => '1', 1 => '2009-07-08 17:36:43', 2 => '2009-07-08 17:36:43', )

Prepare
array ( 0 => 1, 1 => '2009-07-08 00:00:00', 2 => '2009-07-08 00:00:00', )
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://forge.continuent.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
Gilles Rayrat (JIRA)
2009-07-09 10:46:47 UTC
Permalink
[ https://forge.continuent.org/jira/browse/MYO-100?page=all ]

Gilles Rayrat closed MYO-100:
-----------------------------

Resolution: Fixed

Fixed in SVN
Post by Robert Hodges (JIRA)
MySQL datetime values do not bind correctly to PHP
--------------------------------------------------
Key: MYO-100
URL: https://forge.continuent.org/jira/browse/MYO-100
Project: Tungsten Connector
Type: Bug
Components: MySQL protocol
Environment: MySQL 5.0.x, PHP 5.1
Reporter: Robert Hodges
Assignee: Gilles Rayrat
Priority: Blocker
Fix For: 0.6.8
<?php
// Initialize a mysqli object to $mysqli
$mysqli->query('drop database if exists datetimetest');
$mysqli->query('create database datetimetest');
$mysqli->query('create table datetimetest.datetimes (
`recordID` int not null auto_increment primary key,
`startTime` datetime null,
`endTime` datetime null
)');
$mysqli->query('insert into datetimetest.datetimes set startTime = now(), endTime = now()');
$sql = 'select * from datetimetest.datetimes';
echo '<h1>Query</h1>';
$result = $mysqli->query($sql);
while ($row = $result->fetch_array(MYSQLI_NUM)) {
var_export($row);
echo '<br><br>';
}
echo '<h1>Prepare</h1>';
$stmt = $mysqli->prepare($sql);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result(&$startTime, &$endTime, &$creationDate);
$values = array(&$startTime, &$endTime, &$creationDate);
$retval = $stmt->fetch();
while ($retval !== null && $retval !== false) {
var_export($values);
echo '<br><br>';
$retval = $stmt->fetch();
}
$mysqli->query('drop database datetimetest');
?>
Query
array ( 0 => '1', 1 => '2009-07-08 17:36:43', 2 => '2009-07-08 17:36:43', )
Prepare
array ( 0 => 1, 1 => '2009-07-08 00:00:00', 2 => '2009-07-08 00:00:00', )
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://forge.continuent.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
Loading...