0

I have timestamp Thu, 07 May 2015 16:52:43 GMT stored like this:

$timestamp = 1431017563117;

Variable with this value was produced by Java (Location.getTime() method from Android SDK).

I'm trying to store it in database, with mysqli->bind_param(); method. My field has TIMESTAMP type.

I have tried this:

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

And this:

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

It just doesn't work, and MySQLi error gives me nonsense message like this:

Creating default object from empty value in server.php on line 118

How should I do it properly?

Kamil
  • 13,363
  • 24
  • 88
  • 183

1 Answers1

0

I found answer here: Using Mysqli bind_param with date and time columns?

It should be like this:

$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);
Community
  • 1
  • 1
Kamil
  • 13,363
  • 24
  • 88
  • 183