Create a simple Mysql database remotely using a browser

Source: Internet
Author: User

I recently learned about the mysql database and wrote 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:
Use the. php file below.

<Html>
<Head>
<Title> mysql database creation ticket </title>
</Head>
<Body>
<Form method = "post" action = "mkdb. php">
<Table width = 400 border = 1 cellspacing = 0 cellpadding = 0>
<Tr>
<Td align = center colspan = 2> Create a new database </td>
</Tr>
<Tr>
<Td width = 150 align = center> enter the Database Name: </td>
<Td width = 250 align = center>
<Input type = test size = 30 value = database name = databasename>
</Td>
</Tr>
<Tr>
<Td align = center colspan = 2>
<Input type = submit value = create database name = swcode>
</Td>
</Tr>
</Table>
</Form>
<Form method = "post" action = "mkdb. php">
<Table width = 400 border = 1 cellspacing = 0 cellpadding = 0>
<Tr>
<Td align = center colspan = 2> delete an existing database </td>
</Tr>
<Tr>
<Td width = 150 align = center> enter the Database Name: </td>
<Td width = 250 align = center>
<Input type = test size = 30 value = database name = databasename>
</Td>
</Tr>
<Tr>
<Td align = center colspan = 2>
<Input type = submit value = delete database name = swcode>
</Td>
</Tr>
</Table>
</Form>
<Form method = "post" action = "mkdb. php">
<Table width = 500 border = 1 cellspacing = 0 cellpadding = 0>
<Tr>
<Td align = center colspan = 2> Create a table in an existing database </td>
</Tr>
<Tr>
<Td width = 150 align = center> enter the Database Name: </td>
<Td width = 350>
<Input type = test size = 30 value = database name = databasename>
</Td>
</Tr>
<Tr>
<Td width = 150 align = center> enter the table name: </td>
<Td width = 350>
<Input type = test size = 30 value = testable name = tablename>
</Td>
</Tr>
<Tr>
<Td align = center colspan = 2>
<Table width = 500 border = 1 cellspacing = 0 cellpadding = 0>
<Tr>
<Td width = 75 align = center> Field name </td>
<Td width = 175 align = center> <input type = test size = 20 value = idx name = fieldname [1]> </td>
<Td width = 75 align = center> Field Type </td>
<Td width = 175 align = center>
<Select name = type [1] size = 1>
<Option value = integer (10) selected> normal integer </option>
<Option value = tinyint (3)> short integer </option>
<Option value = float ()> single precision floating point </option>
<Option value = double ()> double precision floating point </option>
<Option value = date> date type </option>
<Option value = varchar (255)> variable type </option>
<Option value = char (20)> character type (20 characters) </option>
</Select>
</Td>
</Tr>
<Tr>
<Td width = 75 align = center> Field name </td>
<Td width = 175 align = center> <input type = test size = 20 name = fieldname [2]> </td>
<Td width = 75 align = center> Field Type </td>
<Td width = 175 align = center>
<Select name = type [2] size = 1>
<Option value = integer (10)> General integer </option>
<Option value = tinyint (3)> short integer </option>
<Option value = float ()> single precision floating point </option>
<Option value = double ()> double precision floating point </option>
<Option value = date> date type </option>
<Option value = varchar (255)> variable type </option>
<Option value = char (20)> character type (20 characters) </option>
<Option value = none selected> empty field </option>
</Select>
</Td>
</Tr>
<Tr>
<Td width = 75 align = center> Field name </td>
<Td width = 175 align = center> <input type = test size = 20 name = fieldname [3]> </td>
<Td width = 75 align = center> Field Type </td>
<Td width = 175 align = center>
<Select name = type [3] size = 1>
<Option value = integer (10)> General integer </option>
<Option value = tinyint (3)> short integer </option>
<Option value = float ()> single precision floating point </option>
<Option value = double ()> double precision floating point </option>
<Option value = date> date type </option>
<Option value = varchar (255)> variable type </option>
<Option value = char (20)> character type (20 characters) </option>
<Option value = none selected> empty field </option>
</Select>
</Td>
</Tr>
<Tr>
<Td width = 75 align = center> Field name </td>
<Td width = 175 align = center> <input type = test size = 20 name = fieldname [4]> </td>
<Td width = 75 align = center> Field Type </td>
<Td width = 175 align = center>
<Select name = type [4] size = 1>
<Option value = integer (10)> General integer </option>
<Option value = tinyint (3)> short integer </option>
<Option value = float ()> single precision floating point </option>
<Option value = double ()> double precision floating point </option>
<Option value = date> date type </option>
<Option value = varchar (255)> variable type </option>
<Option value = char (20)> character type (20 characters) </option>
<Option value = none selected> empty field </option>
</Select>
</Td>
</Tr>
<Tr>
<Td width = 75 align = center> Field name </td>
<Td width = 175 align = center> <input type = test size = 20 name = fieldname [5]> </td>
<Td width = 75 align = center> Field Type </td>
<Td width = 175 align = center>
<Select name = type [5] size = 1>
<Option value = integer (10)> General integer </option>
<Option value = tinyint (3)> short integer </option>
<Option value = float ()> single precision floating point </option>
<Option value = double ()> double precision floating point </option>
<Option value = date> date type </option>
<Option value = varchar (255)> variable type </option>
<Option value = char (20)> character type (20 characters) </option>
<Option value = none selected> empty field </option>
</Select>
</Td>
</Tr>
<Tr>
<Td width = 75 align = center> Field name </td>
<Td width = 175 align = center> <input type = test size = 20 name = fieldname [6]> </td>
<Td width = 75 align = center> Field Type </td>
<Td width = 175 align = center>
<Select name = type [6] size = 1>
<Option value = integer (10)> General integer </option>
<Option value = tinyint (3)> short integer </option>
<Option value = float ()> single precision floating point </option>
<Option value = double ()> double precision floating point </option>
<Option value = date> date type </option>
<Option value = varchar (255)> variable type </option>
<Option value = char (20)> character type (20 characters) </option>
<Option value = none selected> empty field </option>
</Select>
</Td>
</Tr>
<Tr>
<Td width = 75 align = center> Field name </td>
<Td width = 175 align = center> <input type = test size = 20 name = fieldname [7]> </td>
<Td width = 75 align = center> Field Type </td>
<Td width = 175 align = center>
<Select name = type [7] size = 1>
<Option value = integer (10)> General integer </option>
<Option value = tinyint (3)> short integer </option>
<Option value = float ()> single precision floating point </option>
<Option value = double ()> double precision floating point </option>
<Option value = date> date type </option>
<Option value = varchar (255)> variable type </option>
<Option value = char (20)> character type (20 characters) </option>
<Option value = none selected> empty field </option>
</Select>
</Td>
</Tr>
<Tr>
<Td width = 75 align = center> Field name </td>
<Td width = 175 align = center> <input type = test size = 20 name = fieldname [8]> </td>
<Td width = 75 align = center> Field Type </td>
<Td width = 175 align = center>
<Select name = type [8] size = 1>
<Option value = integer (10)> General integer </option>
<Option value = tinyint (3)> short integer </option>
<Option value = float ()> single precision floating point </option>
<Option value = double ()> double precision floating point </option>
<Option value = date> date type </option>
<Option value = varchar (255)> variable type </option>
<Option value = char (20)> character type (20 characters) </option>
<Option value = none selected> empty field </option>
</Select>
</Td>
</Tr>
<Tr>
<Td width = 75 align = center> Field name </td>
<Td width = 175 align = center> <input type = test size = 20 name = fieldname [9]> </td>
<Td width = 75 align = center> Field Type </td>
<Td width = 175 align = center>
<Select name = type [9] size = 1>
<Option value = integer (10)> General integer </option>
<Option value = tinyint (3)> short integer </option>
<Option value = float ()> single precision floating point </option>
<Option value = double ()> double precision floating point </option>
<Option value = date> date type </option>
<Option value = varchar (255)> variable type </option>
<Option value = char (20)> character type (20 characters) </option>
<Option value = none selected> empty field </option>
</Select>
</Td>
</Tr>
<Tr>
<Td width = 75 align = center> Field name </td>
<Td width = 175 align = center> <input type = test size = 20 name = fieldname [10]> </td>
<Td width = 75 align = center> Field Type </td>
<Td width = 175 align = center>
<Select name = type [10] size = 1>
<Option value = integer (10)> General integer </option>
<Option value = tinyint (3)> short integer </option>
<Option value = float ()> single precision floating point </option>
<Option value = double ()> double precision floating point </option>
<Option value = date> date type </option>
<Option value = varchar (255)> variable type </option>
<Option value = char (20)> character type (20 characters) </option>
<Option value = none selected> empty field </option>
</Select>
</Td>
</Tr>
</Table>
</Td>
</Tr>
<Tr>
<Td align = center colspan = 2>
<Input type = submit value = create table name = swcode>
</Td>
</Tr>
</Table>
</Form>
<Form method = "post" action = "mkdb. php">
<Table width = 400 border = 1 cellspacing = 0 cellpadding = 0>
<Tr>
<Td align = center colspan = 2> delete an existing table </td>
</Tr>
<Tr>
<Td width = 150 align = center> enter the Database Name: </td>
<Td width = 250 align = center>
<Input type = test size = 30 value = database name = databasename>
</Td>
</Tr>
<Tr>
<Td width = 150 align = center> enter the table name: </td>
<Td width = 250 align = center>
<Input type = test size = 30 value = testable name = tablename>
</Td>
</Tr>
<Tr>
<Td align = center colspan = 2>
<Input type = submit value = Delete table name = swcode>
</Td>
</Tr>
</Table>
</Form>
</Body>
</Html>



Mkdb. php: Use the function to contact mysql.

<Html>
<Head>
<Title> mysql database creation result </title>
<? Php
Function showdb ($ result)
{
Echo "<center> <table border = 1 width = 350 cellspacing = 0 cellpadding = 0>
<Tr>
<Td width = 100 align = center> database No. </td>
<Td width = 250 align = center> database name </td>
</Tr> "; $ I = 0;
While ($ row = mysql_fetch_array ($ result ))
{
$ I = $ I + 1;
Echo "<tr> <td width = 100 align = center> $ I </td> ";
Echo "<td width = 250 align = center> ";
Echo $ row ["database"];
Echo "</td> </tr> </center> ";
}
}
Function showcol ($ result)
{
Echo "<center> <table border = 1 width = 350 cellspacing = 0 cellpadding = 0>
<Tr>
<Td width = 100 align = center> Field name </td>
<Td width = 250 align = center> Field Type </td>
</Tr> "; $ I = 0;
While ($ row = mysql_fetch_array ($ result ))
{
Echo "<tr> <td width = 100 align = center> ";
Echo $ row ["field"];
Echo "</td> ";
Echo "<td width = 250 align = center> ";
Echo $ row ["type"];
Echo "</td> </tr> </center> ";
}
}
Function showtab ($ result, $ databasename)
{
Echo "<center> <table border = 1 width = 350 cellspacing = 0 cellpadding = 0>
<Tr>
<Td width = 100 align = center> table No. </td>
<Td width = 250 align = center> table name </td>
</Tr> "; $ I = 0;
While ($ row = mysql_fetch_array ($ result ))
{
$ I = $ I + 1;
Echo "<tr> <td width = 100 align = center> $ I </td> ";
Echo "<td width = 250 align = center> ";
Echo $ row ["tables_in _". $ databasename];
Echo "</td> </tr> </center> ";
}
}
Function creatdb ($ dbname)
{
$ Result = mysql_create_db ($ dbname );
If ($ result ){
Echo "<center> <table border = 0 width = 350 cellspacing = 0 cellpadding = 0> <tr> <td align = center> ";
Echo "Echo "</td> </tr> </table> </center> ";}
Else {
Echo "<center> <table border = 0 width = 350 cellspacing = 0 cellpadding = 0> <tr> <td align = center> ";
Echo "Echo "</td> </tr> </table> </center> ";}
}
Function dropdb ($ dbname)
{
$ Result = mysql_drop_db ($ dbname );
If ($ result ){
Echo "<center> <table border = 0 width = 350 cellspacing = 0 cellpadding = 0> <tr> <td align = center> ";
Echo "Echo "</td> </tr> </table> </center> ";}
Else {
Echo "<center> <table border = 0 width = 350 cellspacing = 0 cellpadding = 0> <tr> <td align = center> ";
Echo "Echo "</td> </tr> </table> </center> ";}
}
?>
</Head>
<Body>
<Center> <? Php
$ Result = mysql_connect ();
Switch ($ swcode ){
Case 'create database ':
Creatdb ($ databasename );
Echo "<center> $ Result = mysql_list_dbs ();
Showdb ($ result );
Break;
Case 'delete database ':
Dropdb ($ databasename );
Echo "<center> $ Result = mysql_list_dbs ();
Showdb ($ result );
Break;
Case 'create table ':
If (mysql_select_db ($ databasename ))
{
If (mysql_db_query ($ databasename, "select * from $ tablename "))
Echo "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 "$ Result = mysql_db_query ($ databasename, "show columns from $ tablename ");
Showcol ($ result );
}
Else
{
Echo "}
}
}
Else
Echo "<center> $ Result = mysql_db_query ($ databasename, "show tables ");
If ($ result)
{
Echo "<center> Showtab ($ result, $ databasename );
}
Break;
Case 'delete table ':
If (mysql_select_db ($ databasename ))
{
$ Result = mysql_db_query ($ databasename, "drop table $ tablename ");
If ($ result)
{
Echo "<center> $ Result = mysql_db_query ($ databasename, "show tables ");
If ($ result)
{
Echo "<center> Showtab ($ result, $ databasename );
}
}
Else
{
Echo "<center> $ Result = mysql_db_query ($ databasename, "show tables ");
If ($ result)
{
Echo "<center> Showtab ($ result, $ databasename );
}
}
}
Else
Echo "<center> Break;
Default:
Echo "<center> Break;
}
?>
</Body>
</Html>


When used, you need to separate two files to the apache's directory and use iew.mkdb.html.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.