我在PHP中有一个函数,它应该在数据库中保存一个日期时间戳:
public function advanceLevel(){
$aCurrentdate = getdate();
$sDate = $aCurrentdate['mday']."-".$aCurrentdate['mon']."-".$aCurrentdate['year']." ".$aCurrentdate['hours'].":".$aCurrentdate['minutes'];
$aUserRecord = $this->fetchUserRecord($_SESSION['iRecordnumber']);
$iNewLevel = $aUserRecord[0][5] + 1;
$_SESSION['userlevel'] = $iNewLevel;
unset($_SESSION['aQuestions']);
$this->sPdoQuery=("INSERT INTO `tbl_progress` (`iFK_iUseracount_ID`,`sProgress`,`sDate`) VALUES ('".$_SESSION['iRecordnumber']."','Naar level ".$iNewLevel."','".$sDate."')");
$this->PdoSqlReturnTrue();
$this->sPdoQuery=("UPDATE `tbl_useraccounts` SET `iLevelStatus` = '".$iNewLevel."' WHERE `iUseraccounts_ID` = '".$_SESSION['iRecordnumber']."'");
$this->PdoSqlReturnTrue();
return;
}但是在MySQL数据库中的结果是日期/时间戳,没有任何前导零或尾随零。A picture of the results and the database structure
源http://php.net/manual/en/function.getdate.php
我做错了什么?
发布于 2016-12-04 21:12:19
$this->sPdoQuery=(
"INSERT INTO tbl_progress (iFK_iUseracount_ID,sProgress,sDate)
VALUES (
'".$_SESSION['iRecordnumber']."',
'Naar level ".$iNewLevel."',
NOW()
)";
$this->PdoSqlReturnTrue();
set your column type to TIMESTAMPhttps://stackoverflow.com/questions/40958865
复制相似问题