Reputation: 1417
I use doctrine DBAL 2.5.2 with MySql 5.5
I have created a field with timestamp
type and an ON UPDATE CURRENT_TIMESTAMP
extra.
When I change the content from phpMyAdmin the field is updated and change to the current timestamp, but when I update the content from Doctrine/dbal nothing happen. I mean everything works except the on update
.
I call the update with $app['db']->update('mytable', $data, array('my_id' => $id);
How I can run the on update
trigger from the doctrine/dbal code ?
edit :
I add this code to check if I try to change the date.
if (isset($data['updated'])) unset($data['updated']);
Upvotes: 0
Views: 843
Reputation: 5939
date
field with your $data
at all as an empty string will result in zeroes.I have set up a test project, it works fine:
$connectionParams = ...;
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
$conn->update('user', array('name' => 'X3'), array('name' => 'X2'));
Table:
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`name` text NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Some test data:
INSERT INTO `user` (`id`, `name`, `date`) VALUES
(1, 'A', '0000-00-00 00:00:00'),
(2, 'B', '0000-00-00 00:00:00'),
(3, 'C', '0000-00-00 00:00:00'),
(4, 'F', '0000-00-00 00:00:00'),
(10, 'X2', '2015-11-10 14:47:08');
Can you retest and make sure you have all the parameters correct on the date field?
Upvotes: 1