views:

43

answers:

2

I have the website written in PHP (Kohana) and MySQL. I want to create the installer which would run all the environment tests and, what is the most important (and the most misterious) for me, will deploy the database. What is more, I would like to choose the prefix of the tables in the database and specify the username and password for the admin. Would you please give my some hints how to do it? Or some link to some tutorial? I was trying to google that but when I searched for terms like "PHP website installer" I have found only how to install PHP.

The most important for me is the process of deploying database with user-defined tables prefix. How should I store the database structure in the file. Should I name the tables using some keyword for the prefix, for example:

%%prefix%%_tableName

or

__prefix__tableName

And what then? Change all the keywords using regular expresions? Is it correct way or is it any better?

+2  A: 

Wordpress has its famous '5-minute install'. It's a great benchmark for simplicity, usability, and power and it does most, if not all, of the things you outlined in your question.

Mike B
+3  A: 

A simple way would be to store the SQL queries in PHP files and have PHP inject the prefix into the SQL and return the string.

Like, if you had a PHP file like this for each of your CREATE TABLE queries:

<?php
/** get_myTable.php **/
return <<<SQL
CREATE TABLE `{$prefix}myTable` ( ... )
SQL;
?>

You could do this in your main code:

<?php
$prefix = 'dbprefix_';

$create_queries = array();
$create_queries[] = include('get_myTable.php');
$create_queries[] = include('get_otherTable.php');

foreach($create_queries as $_query) {
    mysql_query($_query) or trigger_error(mysql_error(), E_USER_WARNING);
}
?>
Atli