I'm trying to learn PDO and apply to an existing Joomla database table ("users"), just for learning purposes. However I keep getting errors with regard to the "lastResetTime" column.
23000 SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'lastResetTime' cannot be null
When the default system makes a user the default value is set to 0000-00-00 00:00:00, although the settings are NOT NULL.
For some reason I cannot pass this value (0000-00-00 00:00:00) in my queries. This is what I have. Could anyone tell me how I can trigger the default value, despite the facct that I cannot provide NULL, nor 0000-00-00 00:00:00 (which is strictly invalid if I'm correct)
<?php
require 'PDO.php';
$table = $prefix."users";
$pdo = new PDO($dsn,$user,$pass,$opt);
$stmt = $pdo->prepare("INSERT INTO $table (username, email, params, registerDate, lastvisitDate, lastResetTime) VALUES(?, ?, ?, now(),now(), ?)");
$stmt->execute(["lalaa","aaaa","",NULL]);
The table is formated as follows:
CREATE TABLE `x7j4o_users` (
`id` int(11) NOT NULL,
`name` varchar(400) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`username` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`email` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`password` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`block` tinyint(4) NOT NULL DEFAULT '0',
`sendEmail` tinyint(4) DEFAULT '0',
`registerDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastvisitDate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`activation` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`params` text COLLATE utf8mb4_unicode_ci NOT NULL,
`lastResetTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Date of last password reset',
`resetCount` int(11) NOT NULL DEFAULT '0' COMMENT 'Count of password resets since lastResetTime',
`otpKey` varchar(1000) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'Two factor authentication encrypted keys',
`otep` varchar(1000) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'One time emergency passwords',
`requireReset` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Require user to reset password on next login'
)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
UPDATE The following doesn't seem to work also
$stmt = $pdo->prepare("INSERT INTO $table (name, username,registerDate,lastvisitDate,lastResetTime) VALUES(?,?,DEFAULT,DEFAULT,DEFAULT)");
$stmt->execute(['aaaa','aaaaaaaa']);
it triggers the error:
22007 SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '0000-00-00 00:00:00' for column 'registerDate' at row 1
If anyone knows how I can use the default value as set in mysql I would be very greatfull.