install script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

install script

Post by shiznatix »

i wanna write a script that automatically creates a database, creates the tables, and creates the fields. i have all the sql laid. how do i do this?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$sql = "CREATE ..... all your sql goes here";

mysql_connect('localhost','user','pass')
mysql_query($sql) or die(mysql_error());
.......

I also recommend you have either as install.php or /install/

and then check to make sure the install file/folder is gone when your site goes live

so in index.php

Code: Select all

if (is_file('install.php'))
     exit('Please delete install.php');
This is so people won't be able to re-install your database.


also might want to chck
http://dev.mysql.com/doc/mysql/en/index.html
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

multiple queries aren't allowed on older versions of MySQL through a single query call.

The only way I know how, outside of command line, is to load the entire file, strip the comments, break apart the commands, and execute each in sequence.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

ok im trying to create the database, i have the username and pass and all that but it dies with the error

"Access denied for user: 'wesmok2_natix@localhost' to database 'wesmok2_forum'"

and yes the username and password are correct. whats up with this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the user doesn't have access rights to that database.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

the database hasnt been created yet...thats what im trying to do

Code: Select all

$sql = "CREATE DATABASE `forum`;";

mysql_connect('localhost', $dbusername, $dbpassword);
mysql_query($sql) or die(mysql_error());
is giving me that error
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

does the user you are running this from have rights to create a database? I'd bet no.
Post Reply