Reputation: 25346
I'm writing binary data to a BYTEA
field in a UTF8 database.
When I run the query through a PHP/PDO prepared statement, I get the error:
FATAL: SQLSTATE[22021]: Character not in repertoire: 7 ERROR: invalid byte sequence for encoding "UTF8": 0x98
Any idea why it's treating binary data as if it should be utf8 encoded?
Upvotes: 1
Views: 1384
Reputation: 25346
Figured it out, the solution is that PG doesn't allow binary data to be passed as a regular 'string' value, it has to be treated as a special 'large object'.
$stmt->bindValue(1, $field_data, PDO::PARAM_LOB);
Upvotes: 2