duanhui1869 2018-06-10 05:36
浏览 53

数据库中的Php time()值不正确

On my website I want to store user's action as a timestamp in my database (so in a bigint type).

I use the php function time().

$date = time();

When I print $date, everything is fine.

But when I store $date in my database (mysql database), I get an incredible value.

I just did it and the value i get is: 20180610051606 which represent the year 641468!!!!

I don't understand what's wrong.

Update:

When I use int type to store the variable $date in the database the value that is stored is 4294967295

Here is my code:

$date = time();
$query = $db->prepare("INSERT INTO table (id,date) values(?, ?)");
$query->execute(array($id, $date));
  • 写回答

1条回答 默认 最新

  • doudeng3008 2018-06-10 11:02
    关注

    Just change your column name as DateValue or something instead of date. and try the following code:

    <?php
        require_once('init.php');
        $datetime = time();
        $con = $db->prepare("INSERT INTO TableName(Name, DateValue) VALUES('Bairavan', $datetime)");
        $con->execute();
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作