Hello,
When creating software, I inherited a method from my previous company of
creating a file, 'createdb.php' that includes
the instructions to create all the database tables and populate them w/default
values.
When deploying, I run the script first and all is setup.
I've included two different segments from files that I've used to create
tables:
The first is an older procedural method, the second is newer OOP code.
...
...
...
/* create admin table if it does not exist */
if ( @ !$tableSet[constAdminStr] )
{
error_log("createdb.php: creating 'hhc.admin' table");
$sqlStr = "CREATE TABLE admin "
. " (id int(11) NOT NULL auto_increment,"
. " username varchar(64) default '',"
. " password varchar(64) default '',"
. " last_login int(12) default 0,"
. " primary key(id, username)"
. ')';
DBAS_MySQLQuery($sqlStr, $db);
/* password: test */
$userStr = constUserName;
$md5Pass = md5(constUserPass);
error_log("createdb: creating admin account '$userStr'");
$sqlStr = "INSERT INTO admin "
. " SET "
. " username='$userStr',"
. " password='$md5Pass'";
DBAS_MySQLQuery($sqlStr, $db);
}
...
...
...
function PRNK_CreateDatabaseTables($dbObject)
{
$debug = 1;
$defE = constDatabaseDefaultEmpty;
$dbObject->DatabaseCreateTable(constDatabaseTableAdmin);
$dbObject->DatabaseCreateField("id", "int(11)", "NOT NULL",
"auto_increment");
$dbObject->DatabaseCreateField("username", "varchar(64)", $defE);
$dbObject->DatabaseCreateField("password", "varchar(64)", $defE);
$dbObject->DatabaseCreateField("primary", "key(id, username)");
$dbObject->DatabaseCreateCommit($debug);
$dbObject->DatabaseCreateTable(constDatabaseTableIdea);
$dbObject->DatabaseCreateField("idea_id", "int(11)", "NOT NULL",
"auto_increment");
$dbObject->DatabaseCreateField("email", "varchar(64)", $defE);
$dbObject->DatabaseCreateField("phone", "varchar(64)", $defE);
$dbObject->DatabaseCreateField("content", "varchar(2048)", $defE);
$dbObject->DatabaseCreateField("votes", "int(11)", "default 0");
$dbObject->DatabaseCreateField("time", "int(11)", "default 0");
$dbObject->DatabaseCreateField("primary", "key(idea_id)");
$dbObject->DatabaseCreateCommit($debug);
$dbObject->DatabaseCreateTable(constDatabaseTableVote);
$dbObject->DatabaseCreateField("vote_id", "int(11)", "NOT NULL",
"auto_increment");
$dbObject->DatabaseCreateField("idea_id", "int(11)", "default 0");
$dbObject->DatabaseCreateField("email", "varchar(64)", $defE);
$dbObject->DatabaseCreateField("primary", "key(vote_id)");
$dbObject->DatabaseCreateCommit($debug);
}
...
...
...
So my question is ... is what I'm doing ok? .. there must be a better way to do
it ... How are you all
doing database table creation for products that need to be deployed on multiple
systems.?
Thanks!
- Ben
ProjectSkyline.com
[EMAIL PROTECTED]_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk
NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com
Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php