Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Form connect to secondary mssql database


Reply


2 Posts   466 Views

Avatar
morganastreal

Community Member, 4 Posts

19 April 2012 at 8:02pm

I found a couple of old post that asked about having a Silverstripe connect to a second database however there didn't seem to be a solution.

What my client requires is for the the forms to submit to a sales database that is running MSSQL on a different server.
The Silverstripe website I have developed uses MySQL as it is more stable.

I have created the forms using the UserDefinedForm module and have added a call into the submission to trigger a custom php file that is meant to connect and insert the data into the external MSSQL database.
The form then continues as normal with the email responses and submission the the Silverstripe database.

I was looking at doing something like the following and to keep it constant with Silverstripe database declare everything inside and array first.

   function submitToCRM( $form ) {
      $crmConfig = array(
         'type' => 'MSSQLDatabase',
         'server' => 'server',
         'username' => 'username',
         'password' => 'password',
         'database' => 'database',
         'secondDB' => 'true'
      );
      
      $crm = mssql_connect( $crmConfig['server'], $crmConfig['username'], $crmConfig['password'], $crmConfig['secondDB'] )
         or die ('cannot connect to CRM');
      
      mssql_select_db ( $crmConfig['database'], $crm )
         or die ( 'Can not select database' );
         
      /* check if details already entered */
      
      /* insert details */
      
      /* close connection */
      $crm = mssql_close();
   }

however this is obviously wrong and I not familar enough with php to workout the syntex for the connect.

Help would be much appreciated.

Kate

Avatar
morganastreal

Community Member, 4 Posts

20 April 2012 at 5:45pm

Issue was in regards to my host company "Quadra Hosting" which does not allow connect to from php to external SQL database when running in a Unix server account.