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 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.

Data Model Questions /

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

How to store a DataObject's table in another database

Go to End

3 Posts   1439 Views


Community Member, 39 Posts

25 May 2017 at 9:09pm


is there any simple way to define another database for a specific DataObject? I know that I can use DB::connect() to create a connection to the other database and this is what I will be doing if I don't find a feature in SilverStripe itself that would do this for me. But then I have to create all the database queries myself - which is not too much of work in this case - but it's certainly more work than what it would be to use the ORM. And I also need to write a table creation query manually.

Thanks for your support! :)

Background: I'm going to implement a feature that allows registered users to upload their own attachments and I don't want them to appear in the assets folder due to security reasons (other members are NOT allowed to be able to see attachments uploaded by others), so storing them in the database makes sense. Also this way I don't have to worry about duplicate filenames in the system. Setting up another database for this is just for keeping the main database light weighted - easier to transfer data between production and development. The databases can reside on the same server and even use the same MySQL user to avoid the hassle with different passwords.


Forum Moderator, 1391 Posts

28 May 2017 at 12:56am

First - sorry, I haven't thought of solution for your original question. But another option might be to use the secure assests module?

Have every user create his own filefolder, maybe based on the emailaddress, or the user ID. It should be possible to secure the folder on creation to be only accessible to the user and Admin...


Community Member, 39 Posts

3 June 2017 at 12:25am

Damned, this forum made me to lose the long answer that I just wrote :(. This has happened to me many times in the past and now it stroke again! Write a message so long that your session expires, click the Post button and then: BOOM! The only thing you can see is an error message telling that you are not logged in anymore. Tell goodbye to your long string of typed letters and watch them fade away. :(

Thanks for your suggestion, martimiz. Now that my answer is buried deep in the graveyard of cyberspace , I will just say shortly that I did develop this feature using secureassets but then I just wanted to switch to use a database for this. It makes certain things more simple, such as data encryption (which I even managed to do with secureassets + encrypt-at-rest + own code, but there were other reasons too to start using a database for this). All the reasons are in the post I just wrote and which can be found at... nowhere! :D

And sorry, no pun intended when I complain about the behaviour of this forum. It's a great forum with just this one inconvenience! :)