Hi guys,
I was wondering how would I go about approaching writing a PHP install script, if you don't know what I mean, think phpBB. When you download the source and upload to the internet, you'd run the install file, and enter all your details for the mySQL table, create the first administrator etc... how do you go about writing these files in PHP?
Ones that create databases on your server basically.. I can't get my head round it. But I'm sure it's pretty straight forward!
Any ideas?
PHP Database Installation Scripts
Moderator: General Moderators
Re: PHP Database Installation Scripts
HA! Easy!
Using the same type of code, you can also create databases. Then you can insert records in to the database (look up the commands, very easy to find.)
If you currently have a mysql database and are using phpmysql, do an export, turn it in to a text file and then use php to read the text file in to MySQL. Of course it's all a little harder than that but at least now you know where to start.
Code: Select all
<?php
mysql_connect("localhost", "root", "root") or die(mysql_error());
@ mysql_select_db("difdatabase") or die(mysql_error());
$sql = "DROP TABLE IF EXISTS table";
mysql_query($sql);
$sql = 'CREATE TABLE `database`.`table` (
`field1` FLOAT NOT NULL ,
`field2` INT NOT NULL ,
`field3` INT NOT NULL
) ';
mysql_query($sql);
If you currently have a mysql database and are using phpmysql, do an export, turn it in to a text file and then use php to read the text file in to MySQL. Of course it's all a little harder than that but at least now you know where to start.
Re: PHP Database Installation Scripts
Ha, thanks. I knew it'd be as simple as that. Yeah creating databases is what I'm after, so when someone runs the install file it'll set up everything nice and easily on the server! No confusing source editing for the end-user.