Drupal 7 PDOException

时间:2011-08-10 20:27:01

标签: database drupal drupal-7

我制作了一个脚本,可以从一个数据库中导入东西并将其放入另一个数据库中;问题是它打破了消息:

  

PDOException:在hcap_import_do()中(/mnt/hgfs/docroot/hcapdrupal/site_drupal/public_html/sites/all/modules/custom/hcap/hcap.module的第215行)。

以下代码:

db_insert('hcap_candidates')->fields(array(
  'id' => $e['old_id'],
  'pic' => $e['logo'],
  'placed' => $e['placed'],
  'title' => $e['title'],
  'name' => $e['name'],
  'interim' => $e['interim'],
  'permanent' => $e['permanent'],
  'birth' => $e['birth'],
  'marital_status' => $e['marital'],
  'adress' => $e['address'],
  'city' => $e['city'],
  'postal' => $e['postal'],
  'phone_home' => $e['phone_home'],
  'phone_work' => $e['phone_work'],
  'phone_mobile' => $e['phone_mobile'],
  'email1' => $e['email1'],
  'email2' => $e['email2'],
  'reg_by' => $e['reg_by'],
  'cand_head' => $e['cand_head'],
  'cand_body' => $e['cand_body'],
  'prominent' => $e['prominent'],
  'broadcast' => $e['broadcast'],
  'cv' => $e['cv'],
  'old_id' => $e['old_id']
))->execute();  // This is line 215.

有没有人知道什么是错的?

2 个答案:

答案 0 :(得分:1)

您可以使用“try ... catch”块来了解有关错误的更多信息。我需要更多的周围代码和表结构来理解查询失败的原因,但语法似乎是正确的。

如果你不确定,这就是PHP中的“try ... catch”块:

<?php
try {
db_insert('hcap_candidates')
  ->fields(
    array(
      'id' => $e['old_id'],
      'pic' => $e['logo'],
      'placed' => $e['placed'],
      'title' => $e['title'],
      'name' => $e['name'],
      'interim' => $e['interim'],
      'permanent' => $e['permanent'],
      'birth' => $e['birth'],
      'marital_status' => $e['marital'],
      'adress' => $e['address'],
      'city' => $e['city'],
      'postal' => $e['postal'],
      'phone_home' => $e['phone_home'],
      'phone_work' => $e['phone_work'],
      'phone_mobile' => $e['phone_mobile'],
      'email1' => $e['email1'],
      'email2' => $e['email2'],
      'reg_by' => $e['reg_by'],
      'cand_head' => $e['cand_head'],
      'cand_body' => $e['cand_body'],
      'prominent' => $e['prominent'],
      'broadcast' => $e['broadcast'],
      'cv' => $e['cv'],
      'old_id' => $e['old_id'],
    )
  )
  ->execute();
}
catch (PDOException $e) {
  print_r($e->getMessage());
}
?>

您的查询可能存在一个简单的问题(没有名为hcap_candidates的表,该表中没有名为marital_status的字段,等等。异常消息应该告诉您需要知道的所有内容。

BTW,print_r只是一种在浏览器中查看输出的快捷方式。您还可以使用watchdogdrupal_set_message ...

答案 1 :(得分:0)

我完全不知道问题,但请确保您已实施以下步骤

1-您在settings.php文件中定义了2个数据库

2-你使用db_set_active(“database2name”);在将数据插入{database2name}

之前