这是我的功能和日期
$data->datecreated = getdate();
下面的代码不会保存在数据库中。为什么?请注意,记录被插入,但 datecreated 字段看起来被忽略
public function generateCode($characters) {
//Generate the code
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
// Get the curent session id of the user
$session = JFactory::getSession();
$session_id = $session->getId();
//Create an stdClass
$data =new stdClass();
$data->sessionid = (integer)$session_id;
$data->captchacode = (string)$code;
$data->datecreated = getdate();
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->delete($db->nameQuote('#__captchasessions'));
$query->where($db->nameQuote('sessionid').'='.$db->quote($session_id));
$db->setQuery($query);
$db->query();
$db->insertObject( '#__captchasessions', $data, id );
return $code;
}
这是表的结构
delimiter $$
CREATE TABLE `ok6ut_captchasessions` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sessionid` varchar(200) DEFAULT NULL,
`captchacode` varchar(10) DEFAULT NULL,
`datecreated` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8$$