dpx86402 2014-01-29 23:09
浏览 45
已采纳

MySQL日期时间显示0000与PHP PDO

I'm having troubles trying to insert a timestamp into MySQL always shows 0000-00-00 00:00:00

The scheme for the table is this:

CREATE TABLE `Rawdata` (
`Exchanger` varchar(30) NOT NULL,
`Timestamp` datetime NOT NULL,
`Last` float NOT NULL,
`Bid` float NOT NULL,
`Ask` float NOT NULL,
 PRIMARY KEY (`Exchanger`,`Timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

And the code of the php :

$query = "INSERT INTO Rawdata (Exchanger,Timestamp,Last,Bid,Ask) VALUES(?,?,?,?,?)";
    $result = $link->prepare($query);
    $result->bindParam(1,$exchanger,PDO::PARAM_STR);
    $result->bindParam(2,$timestamp,PDO::PARAM_STR);
    $result->bindParam(3,$last,PDO::PARAM_STR);
    $result->bindParam(4,$bid,PDO::PARAM_STR);
    $result->bindParam(5,$ask,PDO::PARAM_STR);
    $result->execute();

Also this is the var_dump() of the variables

array(5) { [1]=> string(6) "Mt.Gox" [2]=> string(10) "1391036493" 
[3]=> string(6) "929.00" [4]=> string(6) "929.00" [5]=> string(6) "932.90" } 

I don't know why is not working.. Because in other function i update other table with the same timestamp column and it works :/

What can be wrong?

Thanks in advance

Edit:

The $timestamp variable comes from this:

$apivariable = string(16) "1391038069839089"

then i use the following:

$timestamp = time($apivariable)

Pastebin:

http://pastebin.com/vBn0TBvG

  • 写回答

3条回答 默认 最新

  • dora0817 2014-01-29 23:49
    关注

    Instead of using:

    $result->bindParam(2,$timestamp,PDO::PARAM_STR);
    

    Use:

    $result->bindValue(2,date('Y-m-d H:i:s', $timestamp),PDO::PARAM_STR);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100