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.

Data Model Questions /

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

DataObject specifing a connection name

Go to End

2 Posts   838 Views


Community Member, 2 Posts

15 December 2013 at 4:51am

Edited: 15/12/2013 4:53am


I have a suggestion about the features of DataObjects. What about adding the ability to specify a connection name that a specific DataObject should need to use. There are situations that some tables are managed by Silverstripe but are located somewhere else or at different database name.


$db = new MySQLDatabase(array(
		'server' => 'localhost',
		'username' => 'myUsername',
		'password' => 'myPassword',
		'database' => 'myDatabase'
DB::setConn($db, 'external');


class MyDataObject extends DataObject
	public static $conn = 'external';

	public static $db = array(
		'IsActive' => 'Boolean'

	public function getCMSFields()
		return new FieldList(
			new CheckboxField('IsActive')

Kind regards,


Forum Moderator, 1379 Posts

24 December 2013 at 1:58am

Edited: 24/12/2013 1:58am


Thanks for willing to contribute to SilverStripe! Propositions won't always be picked up from within these forums though. Please check out this documentation on how to contibute:

In the mean time, as to multiple db connections, there are some solutions/workarounds around. For example:

I remember a discussion about this a short while ago in the core developers group ( but I can't seem to find it just now...

Basically afaik you cannot work with multiple connections at the same time, but you can switch between connections if need be.