1

当用户在我的 Drupal 7 站点上填写表格时,我需要该信息进入远程 MS SQL 服务器数据库。它本质上是一个预订系统,所以他们填写日期/时间和姓名等详细信息,当他们点击提交时,需要将这些字段推送到远程 MS SQL 数据库中。

我想知道a)这是否可能,b)我该如何实施?

4

2 回答 2

2

A. Yes it is possible.

B. I recommend the below way, which is also the "Drupal" way of doing it.

  1. Establish a connection to the remote database. Have a look here if you want to do it in your code, or have a look here if you want Drupal to take care of it by configuring settings.php. The key to switching between databases are db_set_active($database).
  2. Run the queries you'd like to run against the MSSQL database. Just remember to put switch between the databases using db_set_active().
于 2011-09-27T07:31:24.773 回答
0

You can create a custom form in Drupal easily using its Form API in a custom module. In the submit handler for your form, you can insert the submitted data to your MS SQL database using any library avaiable in your PHP environment. Connection to the database is the tricky part, especially if your Drupal host is not running a Microsoft OS. In Drupal 7 running on IIS, you can use Drupal's Database API with the MS SQL driver. If your are not on IIS or Drupal 7, this is also doable without Drupal's Database API using PDO ODBC with unixODBC and FreeTDS. I did it, but I had a major issue when using typed bound parameters in my query, see Using typed bound parameters with PHP PDO-ODBC, unixODBC and FreeTDS.

That said, integration of applications at the database level is a bad idea. Such integration is tightly coupled. Any change to the schema of your MS SQL database or they way actual data are stored in columns will break your form submission. The best would be to have your reservation system provides a remote API to insert new data.

于 2011-09-27T07:31:59.577 回答