【问题标题】:Error while inserting ? as a value in mysql using Perl [closed]插入时出错?使用 Perl 作为 mysql 中的值 [关闭]
【发布时间】:2014-10-28 23:56:33
【问题描述】:

我在mysql 中插入一个URL。 URL 有?。因此,在使用 Perl 插入时,会出现如下错误。

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax

查询:

insert into TEST_DB values (1, 'http://website.com/hfsda/xxx-xxx-xx/?xxxx=cccd');

我也尝试使用\? 转义?,但没有成功。

有什么想法吗?

【问题讨论】:

标签: mysql perl


【解决方案1】:

我不相信你说的是真的。我相信您实际上要求执行不同的查询。找出你实际执行了什么。


经过测试。

use strict;
use warnings;

use DBI qw( );

my $host   = 'localhost';
my $db     = '...';
my $user   = '...';
my $passwd = '...';

my $dbh = DBI->connect(
   "dbi:mysql:host=$host;database=$db",
   $user, $passwd,
   { PrintError => 0, RaiseError => 1 },
);

$dbh->do(q{
   CREATE TEMPORARY TABLE TempTable (
             id  INT,
             url VARCHAR(255)
          )
});

$dbh->do(q{
   INSERT INTO TempTable VALUES
          ( 1, 'http://website.com/hfsda/xxx-xxx-xx/?xxxx=cccd' )
});

print("ok\n");

【讨论】:

  • 我问的问题不是问题。实际上,单引号出现在较早的文本之间,并且在“?”附近显示错误。所以谢谢你的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-25
  • 1970-01-01
  • 2022-12-15
  • 2016-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多