将 json 字符串插入 mysql

insert json string into mysql

我想在 mysql 数据库中存储 json 字符串。 但是好像有一些引用问题,我搞不懂。

use DBI;
use JSON;

#some staff

my $json_string = encode_json \%DB;

#DBI CONNECTION...

# insert data into the links table
my $sql = "INSERT INTO `tech_nodes` (`meta`).
    VALUES(?)";
my $stmt = $dbh->prepare($sql);
$stmt->bind_param(1, $json_string );

# execute the query
$stmt->execute();

错误:

DBD::mysql::st execute failed: 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('{\"techs\":{\"A\":{\"B\":null,\"techs\":{\"stack.tc' at line 1 at ./stacks.pl line 121. DBD::mysql::st execute failed: 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('{\"techs\":{\"A\":{\"B\":null,\"techs\":{\"stack.tc' at line 1 at./stacks.pl line 121.

Table 描述:

CREATE TABLE IF NOT EXISTS `tech_nodes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `meta` MEDIUMTEXT NOT NULL,
  `generated_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

尝试删除 meta 后右括号后的句号。