我在 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
我做错了什么?
最佳答案
$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 TIMESTAMP
关于php - 字符串分钟数中缺少零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40958865/