2011-05-25 56 views
1

我有一个特别棘手的问题,我必须解决但尚未破解坚果。 我已经在drupal问题队列中发布了这个消息,但我可能会被忽略。这里是链接到Drupal Issue 1061458将数据插入表中时发生Drupal数据库错误:Escaped Quotes?

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

我想在每次有人到达一个页面时插入一个插入,所以我把一个愚蠢的空白页与创建内容,然后我把我的动态块在那里运行我的代码从模块。我使块调用捕获用户的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. 

与那些确切转义引号然后在这里在块功能

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

其中IP和组上面设置有问题的代码。这里是从模块安装文件db格式化

$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为空并设置自动增量值。运行cron并刷新缓存。块缓存已关闭。我甚至尝试使用%b作为二进制数据输入,但不使用。我试图删除替换值和硬编码数字,而不是运气。我试着在db调用之后立即执行这个调用,并且它仍然失败,所以我不认为这是块的错误。我甚至尝试用此代码进行更安全的db_write_record调用

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

但是没有运气,任何人有任何想法?

回答

4

集团是一个保留字,重命名列 http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

+0

或者你可以说group_landing_connection.group “例外:遵循一个合格的名字一个时期必须是一个标识符一个字,所以它不需要被引用即使它是保留的“ 但我只是将其重命名 – AllisonC 2011-05-25 15:20:30

+0

你是上帝!这正是问题所在。我什至不知道,MySQL已经保留的话,他们为什么不教这个!好吧,非常感谢你。 – coolestdude1 2011-05-25 15:43:26

+0

在SQL中可能有特殊意义的所有单词都被保留(然后还有更多)。组是由于“GROUP BY”。请参阅http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html获取完整列表。 – Berdir 2011-05-25 18:50:20

相关问题