Niche recently to learn MySQL database, and write a simple program to create a MySQL database remotely with IE, this program is suitable for people who know nothing about MySQL database, can easily create MySQL database and database of various types of tables, and is completely graphical interface, You can even an SQL statement do not know, I wrote this program may still be very humble, here I only think of a role, I hope you can constantly improve this program, do a real sense of the GUI of the MySQL manager.
This program is divided into two files:
Mkdb.htm: Collect user information and use it for the following. php files.
<title>MySQL Database Creation order</title>
mkdb.php: Contact MySQL via the function.
<title>MySQL Database creation results</title>
function showdb ($result)
{
echo "
Database ordinal |
Database name |
"; $i = 0; while ($row =mysql_fetch_array ($result)) {$i = $i +1; echo "
$i | "; echo "
"; echo $row ["Database"]; echo " |
"; }} function Showcol ($result) {echo '
Field name |
Field type |
"; $i = 0; while ($row =mysql_fetch_array ($result)) {echo "
"; echo $row ["Field"]; echo " | "; echo "
"; echo $row ["Type"]; echo " |
"; }} function ShowTab ($result, $DATABASENAME) {echo '
Table number |
Table name |
"; $i = 0; while ($row =mysql_fetch_array ($result)) {$i = $i +1; echo "
$i | "; echo "
"; echo $row ["Tables_in_". $DATABASENAME]; echo " |
"; }} function Creatdb ($dbname) {$result =mysql_create_db ($dbname); if ($result) {echo '
"; echo "$dbname created successfully! "; echo " |
";}
else{
echo "
"; echo "Creation failed! "; echo " |
";}
}
function dropdb ($dbname)
{
$result =mysql_drop_db ($dbname);
if ($result) {
echo "
"; echo "$dbname successfully deleted! "; echo " |
";}
else{
echo "
"; echo "Delete failed! "; echo " |
";}
}
?>
The database creation results are as follows:
$result =mysql_connect ();
Switch ($SWCODE) {
Case ' CREATE database ':
Creatdb ($DATABASENAME);
echo "
The current list of databases is as follows:
";
$result =mysql_list_dbs ();
SHOWDB ($result);
Break
Case ' Delete database ':
Dropdb ($DATABASENAME);
echo "
The current list of databases is as follows:
";
$result =mysql_list_dbs ();
SHOWDB ($result);
Break
Case ' CREATE TABLE ':
if (mysql_select_db ($DATABASENAME))
{
if (Mysql_db_query ($DATABASENAME, "select * from $TABLENAME"))
echo "
$TABLENAME table already exists in the database: $DATABASENAME. Please check the table name!
";
Else
{
$string = "CREATE TABLE". $TABLENAME. " (";
if ($TYPE [1]<> "NONE") $string = $string. $FIELDNAME [1]. " ". $TYPE [1];
for ($i =2; $i <=10; $i + +)
{
if ($TYPE [$i]<> "NONE") $string = $string. ",". $FIELDNAME [$i]. " ". $TYPE [$i];
}
$string = $string. ")";
$result =mysql_db_query ($DATABASENAME, "$string");
if ($result)
{
echo "
Successfully created $TABLENAME table in database: $DATABASENAME!
";
$result =mysql_db_query ($DATABASENAME, "SHOW COLUMNS from $TABLENAME");
Showcol ($result);
}
Else
{
echo "
The action to create $TABLENAME table in database: $DATABASENAME failed! Please check the cause!
";
}
}
}
Else
echo "
This database does not exist! Please check the database name.
";
$result =mysql_db_query ($DATABASENAME, "SHOW TABLES");
if ($result)
{
echo "
In the ". $DATABASENAME." The tables that already exist are as follows:
";
ShowTab ($result, $DATABASENAME);
}
Break
Case ' Delete table ':
if (mysql_select_db ($DATABASENAME))
{
$result =mysql_db_query ($DATABASENAME, "DROP TABLE $TABLENAME");
if ($result)
{
echo "
Successfully in database ". $DATABASENAME." The table ". $TABLENAME." Delete
";
$result =mysql_db_query ($DATABASENAME, "SHOW TABLES");
if ($result)
{
echo "
In the ". $DATABASENAME." The tables that already exist are as follows:
";
ShowTab ($result, $DATABASENAME);
}
}
Else
{
echo "
In the database ". $DATABASENAME." The table ". $TABLENAME." is not in the Delete!
";
$result =mysql_db_query ($DATABASENAME, "SHOW TABLES");
if ($result)
{
echo "
In the ". $DATABASENAME." The tables that already exist are as follows:
";
ShowTab ($result, $DATABASENAME);
}
}
}
Else
echo "
Database ". $DATABASENAME." does not exist!
";
Break
Default
echo "
You didn't do anything!
";
Break
}
?>
When using, you need to put two files in the Apache Access directory, and use IE to access the mkdb.html.