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

标签 php mysql

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

相关文章:

mysql - 记录难以辨认的文件

php - 多个选项卡,多个 while

PHP使用select语句在SQL中打印表

php - Jquery跨域登录与PHP session

PHP:删除MySQL中的特定行

PHP 位掩码在应该为假时说真

MySQL `WHERE ` 给出匹配 0 的意外结果

Python:无法迭代模拟对象中的模拟数据库值

javascript - 无法重现 Wordpress 4.2 持久 XSS 漏洞

php - 从数据库检索数据后如何操作