views:

54

answers:

2

I am trying to figure out how one would start the setup of a small CMS.

I have the groundwork built, but the step of creating the database tables in mysql, should this all be done at once in a install.php file? Is there a preferred method for creating many tables at once, even if I don't need to insert data into them at this time?

+1  A: 

You can

  • Import the schema file to your database prior to deploying the application

  • You can have a script that creates the schema

  • You can have a script that makes any changes to the current schema (for upgrades)

For a small CMS, I'd just keep the SQL in a schema file and import it when I need it.

You could also do a database copy from your dev -> live system. So you make the changes in the dev database as you need them and then push them to the live database. Something like SQLCompare for SQL Server works well.

Wordpress does the install.php route, where you have to enter your credentials and such for the target database and it then pushes the changes to it.

Mr-sk
I didn't realize I could use a schema file. Is this basically a dump file with a bunch of commands? How does php execute a command to load up a schema file?
Nic Hubbard
you can use export->SQL->structure in phpmyadmin for this.
Talvi Watia
A: 

If you're going to be distributing your application for 3rd parties to install on their own servers, a very common approach is to provide (as you said) a simple install.php file. If your application is more complicated, often times an installation directory will come packaged. The user installing the application opens this in a browser, where your script typically does a few things:

  • Check PHP installation - verify (using function_exists()) all the required functions (and thus libraries) are installed and available. Alert the user of anything missing.
  • Allow the user to enter their configuration parameters - application specific settings required. Typically database hostname, username & password.
  • Test database connection - if successful, load initial tables. Commonly you keep your base schema file stored as a SQL file, so the application pushes this through the native mysql client, or issues the individual SQL commands directly.
Tyson