Jump to content

create database & table


funbinod

Recommended Posts

i'm trying to make a install script. for that i wish to CREATE a DATABASE and at the same time CREATE some TABLEs for it with a single form submit? for this can DATABASE be selected within the "CREATE TABLE" query? if yes how? or there is any other idea?

 

Link to comment
Share on other sites

no! there is not my answer. i've read this throughly. and i know how to create DATABASE and TABLE.

i'm trying these two queries to be done with single SUBMIT and i failed

$sql = ("CREATE DATABASE mimosa_cashier");mysqli_query($connect, $sql) or die ("Error creating database: " . mysqli_error($connect));// create tables$sql2 = ("CREATE TABLE info(company CHAR(50), address CHAR(50), email CHAR(50), phone CHAR(15), user CHAR(10), pass CHAR(10))");mysqli_query($connect, $sql2) or die ("Error creating table 'info': " . mysqli_error($connect));
Edited by funbinod
Link to comment
Share on other sites

I've never tried that. Put them in the same query, see what happens, and report back.

Link to comment
Share on other sites

I've never tried that. Put them in the same query, see what happens, and report back.

i've thought of trying it differently.

 

to create a connect string without database.

and after the query of database creation, create another connect string with the database and use create table query.

 

but i've to fix my error reporting problem for form validation that i've asked for support here-

 

http://w3schools.invisionzone.com/index.php?showtopic=50146

 

do u have solution for this either...????

Link to comment
Share on other sites

After thinking about it more, you probably need to do it in two steps because you'll need two connect scripts. The second connect targets the DB that didn't exist in the first.

 

What's the reason you need to do it in one step or is this a hypothetical?

Edited by niche
Link to comment
Share on other sites

i want to make a install script. for this complete database should be installed at a time & in a single process file i have to do this. and i succeeded in it like this....

<?phpdate_default_timezone_set('Asia/Kathmandu');// set mysql variables$db_host = 'localhost';$db_dbase = 'mimosa_cashier';$db_user = 'root';$db_pass = '[Removed for safety]';// connect$connect = mysqli_connect($db_host, $db_user, $db_pass);if (!$connect) die("Unable to connect to database: " . mysqli_error($connect));// create database$sql = ("CREATE DATABASE IF NOT EXISTS mimosa_cashier");mysqli_query($connect, $sql) or die ("Error creating database: " . mysqli_error($connect));echo "Database created successfully<br />";mysqli_close($connect);$connect1 = mysqli_connect($db_host, $db_user, $db_pass, $db_dbase);if (!$connect1) die("Unable to connect to database: " . mysqli_error($connect1));// create tables$sql2 = "CREATE TABLE IF NOT EXISTS info(company CHAR(50), address CHAR(50), email CHAR(50), phone CHAR(15), user CHAR(10), pass CHAR(10))";mysqli_query($connect1, $sql2) or die ("Error creating table 'info': " . mysqli_error($connect1));echo "info created successfully<br />";// echo success text	die("<h2>Mimosa Cashier - Basic registered successfully for <span style=color:#F00;text-decoration:underline;>" . $_POST['company']. "</span>!");	die(header("location: admin.php?"));mysqli_close($connect1);
Edited by Ingolme
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...