hadley
hadley

Reputation: 631

BINARY data not inserting into mysql extracted from a BINARY(20) column?

I have some data that I am trying to insert into a table that is retrieved from another table in mysql which has the data type BINARY(20).

The data extracted is in the variable $binary['hash'];

/l÷ˆ8Ô]¿\µK<þeû

When I try to insert into another table using PDO like below, (the column hash is BINARY(20) also)

$q = $dbc -> prepare("INSERT INTO table VALUES (hash) VALUES (?)");
$q -> execute(array($binary['hash']));

I get an error like such,

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES ('\0/l÷ˆ8Ô]¿\µK<þeû')' at line 1'

I notice that the value of $binary['hash'] is different and it is not inserting!

How can I get this working?

Upvotes: 0

Views: 358

Answers (2)

Rahul
Rahul

Reputation: 77926

You have values twice in your SQL statement and that's the error

INSERT INTO table VALUES (hash) VALUES (?)

it shouold be

INSERT INTO table (hash) VALUES (?)

Upvotes: 0

WojtekT
WojtekT

Reputation: 4775

The proper sql statement should be:

INSERT INTO table (hash) VALUES (?)

Without the first VALUES keyword.

Upvotes: 1

Related Questions