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.

Showcase Questions

Feedback and questions about sites in the Community Showcase.

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

Help please..


Reply

5 Posts   1705 Views

Avatar
Nofel

14 July 2011 at 4:48pm Community Member, 2 Posts

I am confused how to create a database in SilverStripe. I got an assignment to build web database applications. On the web there are laws and regulations. In the Admin there are functions on the user uploaded and there are functions to download and view pdf documents. I'm confused early work in SilverStripe. Please help.

Avatar
Sphere

31 July 2011 at 11:36am Community Member, 44 Posts

You know how to write PHP don't you?
You do know how to set up a new database in phpmyadmin?

That's all you need to know. Silverstripe won't create the database for you. Just add the connection details to _config.php in your project (mysite) folder and you should be done setting up.

After changes to objects, models, extensions or decorators etc, run {url here}/dev/build?flush=all

Avatar
swaiba

31 July 2011 at 9:12pm Forum Moderator, 1796 Posts

What Sphere says is very accurate - but I understand that this is very strange - if you have an assignment I am guessing that create a database means creates a database with tables and data in SQL.

Silverstripe is the first time that I've not had to use SQL to create a basic database structure and manage the data (although within my code there is direct SQL).

Hope this helps!

Avatar
kevinstripe

27 May 2014 at 9:30pm Community Member, 10 Posts

it's right, you should know PHP to create database in SilverStripe.

Avatar
Mia

6 September 2014 at 2:03am (Last edited: 6 September 2014 2:04am), Community Member, 8 Posts

You can create the database before installation of your website, and add the db_name to the site installation, or you can change the database later on by editing the config details (config.php):

i.e. database = mydatabase

$databaseConfig = array(
   "type" => 'MySQLDatabase',
   "server" => 'server domain', //localhost if on own computer
   "username" => 'myusername',
   "password" => 'mypassword',
   "database" => 'mydatabase',
   "path" => ''
);

Furthermore, Silverstripe has full ORM functionality, so you never have to worry about the database after that. If for example you wanted to add fields to the database, you do it using php code in the silverstripe object.php file.

You want to add a Company Type to a company object

<?php

class Company extends DataObject{
private static $db = array(
"Type"=>"Varchar(100)"
}
}

Compiling it using url/dev/build will create the extra field in the object on its own.

Here is a full guide:
http://doc.silverstripe.com/framework/en/topics/datamodel