gpt4 book ai didi

php - 字符串分钟数中缺少零

转载 作者:行者123 更新时间:2023-11-29 11:08:56 26 4
gpt4 key购买 nike

我在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com