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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Form connect to secondary mssql database


Go to End


2 Posts   961 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.