Page 1 of 1
Making a SQL installer
Posted: Sun Jun 05, 2005 9:50 am
by Smackie
I have alot of SQL's to install in MySQL and was wondering how I could add all them SQL's at once on an installer?? I want it where each SQL can be installed by a button like all the PM SQl's be installed by one button and if they dont want it they dont have to click it?? can someone help me here?
Thank you
Smackie
Posted: Sun Jun 05, 2005 11:56 am
by Roja
There are a number of ways.
You could create a file of sql statements, and have your php file simply read them in and execute them with mysql_* functions.
You could also do it in the same file, simply setting the sql calls up as members of an array, and then iterating over the array.
You didn't specify if you are dumping data to a database, or simply running schema commands (make table, etc). If you are just creating the db structure, you can use the fantastic adodb-xmlschema, which allows you to make XML files of the db structure, and it will parse them and create the db. It even can take an existing db, and output the XML file for you!
There are a variety of ways.. it depends on what you want more and what you want to avoid.
Posted: Sun Jun 05, 2005 12:10 pm
by Smackie
well i found something i could use but for some reason i keep getting an error
Code: Select all
<?php
include 'opendb.php';
$query = 'CREATE DATABASE main';
$result = mysql_query($query);
mysql_select_db('main') or die('Cannot select database');
$query = 'CREATE TABLE links ('.
'id int(25) NOT NULL auto_increment,'.
'description varchar(255) NOT NULL default,'.
'link varchar(155) NOT NULL default,'.
'filter varchar(55) NOT NULL default,'.
'PRIMARY KEY (id)';
'CREATE TABLE users ('.
'userid int(25) NOT NULL auto_increment,'.
'user_name varchar(25) NOT NULL default,'.
'email_address varchar(155) NOT NULL default,'.
'msn varchar(155) NOT NULL default,'.
'aim varchar(55) NOT NULL default,'.
'yahoo varchar(55) NOT NULL default,'.
'about_me text NOT NULL default,'.
'password varchar(55) NOT NULL default,'.
'show_email varchar(55) NOT NULL default,'.
'show_msn varchar(55) NOT NULL default,'.
'show_aim varchar(55) NOT NULL default,'.
'show_yahoo varchar(55) NOT NULL default,'.
'rank varchar(55) NOT NULL default,'.
'user_level enum('0','1','2','3','4','5') NOT NULL default, '0','.
'signup_date datetime NOT NULL default '0000-00-00 00:00:00','.
'last_login datetime NOT NULL default '0000-00-00 00:00:00','.
'online_time datetime NOT NULL default '0000-00-00 00:00:00','.
'activated enum('0','1') NOT NULL default '0','.
'PRIMARY KEY (userid)';
'CREATE TABLE news ('.
'id int(25) NOT NULL auto_increment,'.
'poster varchar(55) NOT NULL default '','.
'news text NOT NULL default '','.
'filter varchar(55) NOT NULL default '','.
'user_level varchar(55) NOT NULL default '','.
'date datetime NOT NULL default '0000-00-00 00:00:00','.
'PRIMARY KEY (id)';
'CREATE TABLE pm ('.
'id int(6) NOT NULL auto_increment,'.
'user_name varchar(25) NOT NULL,'.
'subject varchar(255) NOT NULL,'.
'message text NOT NULL,'.
'sender varchar(55) NOT NULL,'.
'sent varchar(55) NOT NULL,'.
'new varchar(55) NOT NULL,'.
'date datetime NOT NULL default '0000-00-00 00:00:00','.
'PRIMARY KEY (id)';
$result = mysql_query($query);
include 'closedb.php';
?>
the error is on this line here
'user_level enum('0','1','2','3','4','5') NOT NULL default, '0','.
the error
Parse error: parse error, unexpected T_LNUMBER in /home/deke/public_html/install/tables.php on line 31
Posted: Sun Jun 05, 2005 12:18 pm
by Roja
Thats because you are using single quotes for the code, AND for the sql. It should look like this:
Code: Select all
$query = "CREATE TABLE links (".
"id int(25) NOT NULL auto_increment,".
"user_level enum('0','1','2','3','4','5') NOT NULL default, '0',".
...
"PRIMARY KEY (id)";
Posted: Sun Jun 05, 2005 12:32 pm
by Smackie
yeah i just found that out lol :S i fixed all that but for some reason now

it says i cant "Cannot select database"

everything is set up right i believe:S
Posted: Sun Jun 05, 2005 12:39 pm
by Smackie
Smackie wrote:yeah i just found that out lol :S i fixed all that but for some reason now

it says i cant "Cannot select database"

everything is set up right i believe:S
well now i fixed that now it shows nothing i think everything is working but its not sending anything to the database
