Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a serie of databases

Status
Not open for further replies.

blekfis

Programmer
Oct 19, 2001
38
0
0
SE
Hi,
I would like to make a script that creates a serie of databases. This is what I thought could do the job...


$mysql_access = mysql_connect("localhost", "user", "pass");
$count = 1;
while ($count < 5) {
$query = "CREATE database_" . $count;
mysql_query($query, $mysql_access) or die (mysql(error));
echo "$query<br>";
$count++;
}

I want it to create database_1 -> database_4 (initially), but gives error. How do I...
 
Sorry... Should have been in the first post...

Warning: Wrong parameter count for mysql() in C:\xampp\xampp\htdocs\create_db.php on line 6
 
Correct TonyGroves :)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Correct! It's those small things that's hard to see...

This is being used now:
<?php
$mysql_access = mysql_connect("localhost", "root", "");
$count = 1;
while ($count < 5) {
$query = "CREATE database_" . $count;
mysql_query($query, $mysql_access) or die (mysql_error());
echo "$query<br>";
$count++;
}
?>


Now the error is:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database_1' at line 1


Anyone who can see any other "small things"...? I've changed user to "root" who is granted everything and uses no pass, so that's not the problem...
 
Sorry, was late last night,

<?php
$mysql_access = mysql_connect("localhost", "root", "");
$count = 1;
while ($count < 5) {
mysql_create_db("database_$count") or die (mysql_error());
$count++;
}
?>



______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
As KarveR says, you can use a dedicated PHP function. You could also use a normal query: "CREATE DATABASE database_1".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top