简体   繁体   中英

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?

The proper sql statement should be:

INSERT INTO table (hash) VALUES (?)

Without the first VALUES keyword.

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 (?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM