开发者

Web page installer - database deployment

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?


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);
}
?>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜