Use IE to remotely create a simple Mysql database. John recently learned about Mysql databases and compiled a simple program to remotely create Mysql databases using IE. this program is applicable to anyone who knows nothing about Mysql databases, you can easily create a Mysql database. Recently, I learned how to create a simple program to remotely create a Mysql database using IE. this program is applicable to anyone who knows nothing about the Mysql database, you can easily create Mysql databases and tables of various types in the database, and they are completely graphic interfaces. you may not even know a single SQL statement, the program I have compiled may still be very simple. here I only think of the role of the plug-in. I hope you can constantly improve this program and create a Mysql manager with a real graphical interface.
This program is divided into two files:
Mkdb.htm: collects user information for use in the. php file below.
MYSQL database creation ticket
Mkdb. php: use the function to contact mysql.
MYSQL database creation result
Function showdb ($ result)
{
Echo"
Database No. |
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 No. |
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 deleted successfully! "; Echo" |
";}
Else {
Echo"
"; Echo "failed to delete! "; Echo" |
";}
}
?>
The database creation result is as follows:
$ Result = mysql_connect ();
Switch ($ SWCODE ){
Case 'create database ':
Creatdb ($ DATABASENAME );
Echo" The current database list is as follows:
";
$ Result = mysql_list_dbs ();
Showdb ($ result );
Break;
Case 'delete database ':
Dropdb ($ DATABASENAME );
Echo" The current database list 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 database: $ DATABASENAME. Check 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" The $ TABLENAME table is successfully created in database: $ DATABASENAME! ";
$ Result = mysql_db_query ($ DATABASENAME, "show columns from $ TABLENAME ");
Showcol ($ result );
}
Else
{
Echo" An error occurred while creating the $ TABLENAME table in database: $ DATABASENAME! Check the cause! ";
}
}
}
Else
Echo" This database does not exist! Check the database name.
";
$ Result = mysql_db_query ($ DATABASENAME, "show tables ");
If ($ result)
{
Echo" The following table exists in ". $ DATABASENAME: ";
Showtab ($ result, $ DATABASENAME );
}
Break;
Case 'delete table ':
If (mysql_select_db ($ DATABASENAME ))
{
$ Result = mysql_db_query ($ DATABASENAME, "drop table $ TABLENAME ");
If ($ result)
{
Echo" You have successfully deleted the table ". $ TABLENAME." in the database ". $ DATABASENAME .". ";
$ Result = mysql_db_query ($ DATABASENAME, "show tables ");
If ($ result)
{
Echo" The following table exists in ". $ DATABASENAME: ";
Showtab ($ result, $ DATABASENAME );
}
}
Else
{
Echo" The table ". $ TABLENAME." is not deleted in the database ". $ DATABASENAME! ";
$ Result = mysql_db_query ($ DATABASENAME, "show tables ");
If ($ result)
{
Echo" The following table exists in ". $ DATABASENAME: ";
Showtab ($ result, $ DATABASENAME );
}
}
}
Else
Echo" Database ". $ DATABASENAME." does not exist! ";
Break;
Default:
Echo" You did nothing! ";
Break;
}
?>
When used, you need to separate two files to the apache's directory and use iew.mkdb.html.
...