C Würtz
C Würtz

Reputation: 864

Insert Datetime to Cassandra (by DataStax PHP Driver)

I have a table:

CREATE TABLE agency (
  documentCode ASCII,
  sectionCode ASCII,
  checkedAt TIMESTAMP,

  PRIMARY KEY (franchisedCode, agencyCode)
)
;

I can change the structure of my database, if needed.

I would set a timestamp:

$cassandra = $cluster->connect($keyspace);
$statement = $cassandra->prepare('
  INSERT INTO agency 
  ( documentCode
  , sectionCode
  , checkedAt
  ) VALUES 
  ( :documentCode
  , :sectionCode
  , :checkedAt
  );
');

$arguments = [
    'documentCode'   => $code1,
    'sectionCode'    => $code2,
    'checkedAt'      => $mixed,
];

var_dump($arguments);

$options = new ExecutionOptions([
    'arguments' => $arguments,
]);

$cassandra->execute($statement, $options);

I tested some values for $mixed:

The error message is Fatal error: Uncaught Cassandra\Exception\InvalidArgumentException: Invalid value type

Can you see something wrong? Thanks

Upvotes: 1

Views: 795

Answers (1)

C Würtz
C Würtz

Reputation: 864

Well, I solved my issue. I have to use Object Type: $checkedAt = new \Cassandra\Timestamp($checkedAt);

Upvotes: 1

Related Questions