简体   繁体   English

BINARY数据未插入从BINARY(20)列中提取的mysql中?

[英]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) . 我有一些数据要插入到表中,该表是从mysql中具有数据类型BINARY(20)另一个表中检索的。

The data extracted is in the variable $binary['hash']; 提取的数据位于变量$binary['hash'];

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

When I try to insert into another table using PDO like below, (the column hash is BINARY(20) also) 当我尝试使用如下所示的PDO插入另一个表时,(列哈希也为BINARY(20)

$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; 您的SQL语法有误; 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' 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的'VALUES('\\ 0 / l÷ˆ8Ô]¿\\ µK <þeû')'附近使用

I notice that the value of $binary['hash'] is different and it is not inserting! 我注意到$binary['hash']值不同,并且没有插入!

How can I get this working? 我该如何工作?

The proper sql statement should be: 正确的sql语句应为:

INSERT INTO table (hash) VALUES (?)

Without the first VALUES keyword. 没有第一个VALUES关键字。

You have values twice in your SQL statement and that's the error 您的SQL语句中有两次values ,这就是错误

INSERT INTO table VALUES (hash) VALUES (?) 插入表VALUES(哈希)VALUES(?)

it shouold be 应该是

INSERT INTO table (hash) VALUES (?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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