Write an Install .php Script for Mysql Database

I apologize now to those of you who may feel this question is ‘basic’

But I promise you, I’ve searched the web for Months and have not found the answer to this question anywhere; not even in sitepoint.

I created a site, that requires a database to store information, comes with a CMS; all of that is great; BUT when someone buys the script from me, I need to INSTALL it for them; to make sure the databases are set up properly.

This would be So much Simpler, if I had a script included, that When accessed, installs the database, the tables for the database, with all of it’s proper settings. So that it would be ‘self-installing’

I could then just tell them to Delete the file after they set up their website; and go from there.

This seems like it’s So simple to do; and yet I can’t seem to find a simple walk through to explain HOW it’s done; I know bigger sites like, wordpress and phpbb use ‘self installing .php scripts’ - but - again, i can’t seem to find anywhere to learn how to build one myself.

I’ve peaked at theirs, and the coding is way too complex to decipher; it’s as if they added Extra difficult Code to it, to confuse anyone seeking to do something similar.

Here is what I have so far; BUT i swear it’s wrong…


$sql = 'CREATE TABLE `sitewide`.`videodb` (
`vid_name` VARCHAR( 250 ) NOT NULL ,
`vid_model` VARCHAR( 250 ) NOT NULL ,
`vid_descrip` VARCHAR( 350 ) NOT NULL ,
`vid_date` VARCHAR( 100 ) NOT NULL ,
`vid_duration` VARCHAR( 200 ) NOT NULL ,
`vid_file` VARCHAR( 150 ) NOT NULL ,
`extra1` VARCHAR( 150 ) NULL ,
`extra2` VARCHAR( 150 ) NULL ,
`extra3` VARCHAR( 150 ) NULL


What would also be ‘great’ too is if I could create a Form, that is user friendly so a person can just type in the ‘database name’ ‘username’, ‘password’ - and ‘tablename’ (for example) - and it would automatically put all of these values into the table as well as update any other pages looking to access the ‘tablename’ variable.

I’ve seen other sites scripted to work this way; Don’t see how I can’t find anyone else asking the same question on the web; this is something that clearly ‘can’ be done and is being done; any help from anyone would be greatly appreciate it.

The step that would still be missing is to create the database itself in the first place. For most people using shared hosting they do not have the necessary access to do that via a script and so would need to use the option in their control panel to do that first.

If you want people to be able to enter their database details without having to manually edit the file that contains the info to connect to their database then you’d want a step that writes that information into a file so that it can then be read back whenever you need to connect to the database from within your script.

Another step you might want to add is one to drop the database before trying to create it just in case they decide to rerun the install.

About the only other thing would be to test if the tables have been correctly created and return an appropriate error if things fail to work.

You might also have data you want it to insert into the tables during the install.

That’s about all the extra steps I can think of that you could optionally add depending ion exactly what you need the install to do.

That’s it?

I do know how to connect to the database – i have some of that ‘code’ in a separate file; seems like something would still be missing though…

Before you can use that code you need to first connect to the database.

You then need to use either mysql_query($sql,$db) or mysqli_query($db,$sql) in order to process that query against the database.

Just wondering …

how much would you Charge me, to Write this script for me?

Then, possibly explain it to me over the phone/web/skype, so i can better understand what you did, and why you did it.

I would like the script to install the tables; They can create the database through the control panel of their Hosting company; as that’s not hard to do; even for a novice.

From there, if I had a script that installed the Tables; the site could be self installing and ready to go.

So if possible, i’d love a quote - inbox me if you prefer, or post it here on this thread… thanks for your help; love your suggestions. slightly confused on how to pull it off; but I’m sure It’s something I could Learn.