【问题标题】:MySQL bind_param and date stored as integer (produced by java)MySQL bind_param 和日期存储为整数(由 java 产生)
【发布时间】:2015-07-18 09:52:07
【问题描述】:

我的时间戳Thu, 07 May 2015 16:52:43 GMT 存储如下:

$timestamp = 1431017563117;

具有此值的变量由 Java 生成(Android SDK 中的 Location.getTime() 方法)。

我正在尝试使用mysqli->bind_param(); 方法将其存储在数据库中。我的字段有TIMESTAMP 类型。

我试过这个:

$stmt->bind_param('di', $timestamp, $Id);

还有这个:

$stmt->bind_param('ii', $timestamp, $Id);

它只是不起作用,MySQLi 错误给了我这样的废话:

从第 118 行 server.php 中的空值创建默认对象

我应该如何正确地做呢?

【问题讨论】:

    标签: php datetime mysqli


    【解决方案1】:

    我在这里找到了答案:Using Mysqli bind_param with date and time columns?

    应该是这样的:

    $java_integer_timestamp = 1431017563117;
    
    $unix_timestamp = $java_integer_timestamp / 1000;
    
    $query = "update Table SET DateTimeColumn = FROM_UNIXTIME(?) WHERE Id=?";
    
    // ... prepare statement here
    
    $stmt->bind_param('di', $unix_timestamp, $Id);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-10
      • 1970-01-01
      • 2014-02-18
      • 1970-01-01
      • 2013-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多