gpt4 book ai didi

php - 将数据插入表 : Escaped Quotes? 时出现 Drupal DB 错误

转载 作者:行者123 更新时间:2023-11-29 04:56:29 25 4
gpt4 key购买 nike

我有一个特别棘手的问题需要解决,但还没有解决问题。我已经在 drupal 问题队列中发布了这个,但我可能只是被忽略了。这是 Drupal Issue 1061458 的链接.

这是在我的 centos 机器上使用 apache mysql 和 php 在 Drupal 6 中完成的。

每次有人到达页面时,我都尝试插入一个内容,所以我放了一个愚蠢的空白页面并创建了内容,然后我将我的动态 block 放在那里以从模块运行我的代码。我使 block 调用一个函数,该函数获取用户的 ip 地址并将其与标志一起存储在数据库中,直到该人注册为止。

这是生成的错误

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 'group) VALUES ('','')' at line 1 query: INSERT INTO group_landing_connection (ipaddress,group) VALUES ('','') in /var/www/html/sites/all/modules/MODULE/MODULE.module on line 1130.

有了这些精确的转义引号,这里就是 block 函数中的违规代码

$sql = "INSERT INTO {group_landing_connection} (ipaddress,group) VALUES ('%s','%d')";
db_query($sql,$ip,$group);

其中Ip和group在上面设置。这是模块安装文件中的数据库格式

  $schema['group_landing_connection'] = array(
'fields' => array(
'dbid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, ),
'ipaddress' => array('type' => 'varchar', 'length' => '30', 'not null' => TRUE, ),
'group' => array('type' => 'varchar', 'length' => '10', 'not null' => TRUE, ),
),
'primary key' => array('dbid'),

);

我尝试了很多方法,从将 dbid 设置为 null 到设置自动增量值。运行 cron 并刷新缓存。 block 缓存已关闭。我什至尝试使用 %b 进行二进制数据输入,但没有。我尝试删除替换值和硬编码数字而不是运气。我尝试在一个有效的数据库调用之后立即进行此调用,但它仍然失败,所以我认为这不是 block 的错误。我什至尝试使用这段代码进行更安全的 db_write_record 调用

$data = array(
'ipaddress' => '3',
'group' => '3',
);
drupal_write_record('np_group_landing_connection', $data);

但是没有人有任何想法?

最佳答案

组是保留字,重命名你的列 http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

关于php - 将数据插入表 : Escaped Quotes? 时出现 Drupal DB 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6126040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com