Orsu
Orsu

Reputation: 417

PDO bindValue isn't inserting a date

For work, i have to make an oracle database and mysql one communicate.

On Oracle, i have a vrp table with (among others) a DATECREATION column, in DATE format (alas, it's what SQL developer tells me when i click it). It stores dates in the DD/MON. /YY format. a screenshot of sql developer showing that the DATECREATION column is of type DATE a screenshot of sql developer showing that the DATECREATION column hold values in the dd/mon/yy format

I have to copy these values over to a mysql database. At first, i tried to ignore them and used them as strings; but i will have to manipulate them so i need to have them as date.

So in PHP, i do date('Y-m-d', strtotime($row[26])) and it works fine, turning '24-OCT-19' into 2019-10-24

I then try to insert this in my Mysql database, doing the following :

$stmt = $conn->prepare("INSERT INTO [...] VALUES (?, ? [...]);
$stmt->bindValue(27, date('Y-m-d', strtotime($row[26]))); (yes there are a lot of columns)
$stmt->execute($row);

if i echo the data it looks fine, i didn't mixed up my indexes since the adjacents columns don't get the date inserted. However, the 27th column receives a 0000-00-00.

No errors or warning are raised, so i don't even know how to debug this.

Thank you.

Upvotes: 1

Views: 348

Answers (1)

nbk
nbk

Reputation: 49373

Rewrite your oracle select statement.

And use a following text conversion, to get a mysql date format as string

TO_CHAR( SYSDATE, 'YYYY-MM-DD HH24:MI:SS' )

Upvotes: 1

Related Questions