【问题标题】:Drupal 7 database API error "You have an error in your SQL syntax"Drupal 7 数据库 API 错误“您的 SQL 语法有错误”
【发布时间】:2012-06-16 17:34:11
【问题描述】:

使用以下代码:

    db_update('nodesequence_nodes')
  ->fields(array(
    'order' => 1,
  ))
  ->condition('nid', 1, '=')
  ->condition('nsid', 1, '=')
  ->execute();

我收到以下错误:

PDOException: SQLSTATE[42000]: 语法错误或访问冲突:1064 您的 SQL 语法有错误;检查手册 对应于您的 MySQL 服务器版本,以便使用正确的语法 在第 1 行靠近 'order='1' WHERE (nid = '1') AND (nsid = '1')':更新 {nodesequence_nodes} SET order=:db_update_placeholder_0 WHERE (nid = :db_condition_placeholder_0) 与 (nsid = :db_condition_placeholder_1) ;数组 ( [:db_update_placeholder_0] => 1 [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => 1 ) 在 nodesequence_init() 中(第 13 行) /var/www/eventbooking2/sites/all/modules/nodesequence/nodesequence.module)。

很抱歉,我无法提供更多见解,但我希望你能提供。

简单的db_update 代码在我看来应该可以工作,但我不知道为什么不能。

数据库架构:

        $schema['nodesequence_nodes'] = array(
        'description' => 'Relating nodesequences to their consituent nodes.',
        'fields'     => array(
            'nsid'   => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
            'nid'    => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
            'order'  => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
        ),
        'primary key' => array('nsid', 'nid'),
    );

【问题讨论】:

  • 对我来说看起来不错。这是自定义表吗?如果是这样,你能显示你的表模式吗?
  • 我刚刚包含了数据库模式。谢谢

标签: database api drupal-7


【解决方案1】:

您不能在表中使用名为“order”的列,因为这是保留字。您需要将其更改为其他内容。

更多信息在这里http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html看看表9.2

【讨论】:

  • 你说的很对。我从来没有想过我使用的是保留字。非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-27
  • 1970-01-01
  • 2016-01-24
  • 2020-03-10
  • 2018-08-29
  • 2019-08-29
相关资源
最近更新 更多