English 中文(简体)
Drupal数据库在将数据插入表时出错:转义引号?
原标题:Drupal DB Error when Inserting data into table : Escaped Quotes?

I am having a particularly tough issue i have to solve but have yet to crack the nut. I have posted about this in the drupal issue queue but i might just be getting ignored. Here is the link to Drupal Issue 1061458.

这是在我的centos盒子上的Drupal 6中使用apachemysql和php完成的。

我试图在每次有人到达页面时进行插入,所以我把一个愚蠢的空白页面放在那里,创建内容,然后我把我的动态块放在那里运行模块中的代码。我使块调用成为一个函数,该函数获取用户的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和组设置在上面。这是模块安装文件中的数据库格式

  $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并刷新缓存。块缓存已关闭。我甚至尝试使用%b输入二进制数据,但没有。我试着删除替换值和硬编码数字,但运气不好。我试着在一个有效的数据库调用之后立即进行这个调用,但仍然失败了,所以我不认为这是块的错。我甚至尝试使用以下代码进行更安全的db_write_record调用

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

但运气不好,有人有什么想法吗?

最佳回答

Group is a reserved word, rename your column http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签