绘芯展厅在线 - 专业的数字展厅设计平台!

滑轨屏|幻影成像|互动投影|全息柜|-@绘芯展厅在线

php数据库管理程序设计

时间:2016-08-01 09:56来源:未知 作者:admin 点击:
php数据库管理程序设计

<?php
function logon() {
global $PHP_SELF;
setcookie("mysql_web_admin_username");
setcookie("mysql_web_admin_password");
echo "<html><head><title>
数据库管理</title></head><body>";
echo "<table width=100% height=100%><tr><td><center>;\n";
echo "<table cellpadding=2><tr><td bgcolor=#a4a260><center>\n";
echo "<table cellpadding=20><tr><td bgcolor=#ffffff><center>\n";
echo "<h1>
数据库管理登录界面</h1>\n";
echo "<form action='$PHP_SELF'>\n";
echo "<input type=hidden name=action value=logon_submit>\n";
echo "<table cellpadding=5 cellspacing=1>\n";
echo "<tr><td>
账号 </td><td><input type=text name=username></td></tr>";
echo "<tr><td>
密码 </td><td><input type=passwordname=password></td></tr> ";
echo "</table><p>";
echo "<input type=submit value=
确认><input type=reset value=清除><br>";
echo "</form>";
echo "</center></td></tr></table>";
echo "</center></td></tr></table>";
echo "</center></td></tr></table>";
echo "</body></html> ";
}
function logon_submit() {
global $username, $password, $PHP_SELF;
setcookie("mysql_web_admin_username", $username );
setcookie("mysql_web_admin_password", $password );
echo "<html><head><META HTTP-EQUIV=Refresh CONTENT='0; URL=$PHP_SELF?action=listDBs'>";
echo "</head></html>";
}
function echoQueryResult() {
global $queryStr, $errMsg;
if( $errMsg == "" ) $errMsg = "
完成";
if( $queryStr != "" ) {
echo "<table cellpadding=5>\n";
echo "<tr><td>Query</td><td>$queryStr</td>;</tr>\n";
echo "<tr><td>Result</td><td>$errMsg</td></tr>\n";
echo "</table><p>\n";
}
}
function listDatabases() {
global $mysqlHandle, $PHP_SELF;
echo "<h1>
目前已存在的数据库列表</h1>\n";
echo "<form action='$PHP_SELF'>\n";
echo "<input type=hidden name=action value=createDB>\n";
echo "<input type=text name=dbname>\n";
echo "<input type=submit value='
新建数据库'>\n";
echo "</form>\n";
echo "<hr>\n";
echo "<table cellspacing=1 cellpadding=5>\n";
$pDB = mysql_list_dbs($mysqlHandle);
$num = mysql_num_rows($pDB);
for( $i = 0; $i < $num; $i++ ) {
$dbname = mysql_dbname( $pDB, $i );
echo "<tr><td>$dbname</td>";
echo "<td><a href=$PHP_SELF?action=listTables&dbname=$dbname>
数据表</a></td>";
echo "<td><a href='$PHP_SELF?action=dropDB&dbname=$dbname'";
echo "onClick=\"return confirm('Drop Database \'$dbname\'?')\">
删除</a></td>";
echo "</tr>\n";
}
echo "</table>\n";
}
function createDatabase(){
global $mysqlHandle, $dbname, $PHP_SELF;
mysql_create_db($dbname, $mysqlHandle );
listDatabases();}
function dropDatabase() {
global $mysqlHandle, $dbname, $PHP_SELF;
mysql_drop_db( $dbname, $mysqlHandle );
listDatabases();}
function listTables() {
global $mysqlHandle, $dbname, $PHP_SELF;
echo "<h1>
数据库表列表</h1>\n";
echo "<p class=location>$dbname</p>\n";
echoQueryResult();
echo "<form action='$PHP_SELF'>\n";
echo "<input type=hidden name=action value=
新建数据库表>\n";
echo "<input type=hidden name=dbname value=$dbname>\n";
echo "<input type=text name=tablename>\n";
echo "<input type=submit value='
新建数据库表'>\n";
echo "</form>\n";
echo "<form action='$PHP_SELF'>\n";
echo "<input type=hidden name=action value=query>\n";
echo "<input type=hidden name=dbname value=$dbname>\n";
echo "<input type=text size=40 name=queryStr>\n";
echo "<input type=submit value='
SQL语句查询'>\n";
echo "</form>\n";
echo "<p><hr>\n";
$pTable = mysql_list_tables( $dbname );
if( $pTable == 0 ) {
$msg = mysql_error();
echo "<h3>Error : $msg</h3><p>\n";
return; }
$num = mysql_num_rows( $pTable );
echo "<table cellspacing=1 cellpadding=5>\n";
for( $i = 0; $i < $num; $i++ ) {
$tablename = mysql_tablename( $pTable, $i );
echo "<tr><td>$tablename</td><td>";
echo "<a href='$PHP_SELF?action=viewSchema&dbname=$dbname&tablename=$tablename'>
结构</a>\n";
echo "</td><td>";
echo "<a href='$PHP_SELF?action=viewData&dbname=$dbname&tablename=$tablename'>
记录</a>\n";
echo "</td><td> ";
echo "<a href='$PHP_SELF?action=dropTable&dbname=$dbname&tablename=$tablename' ";
echo "onClick=\"return confirm('Drop Database \'$dbname\'?')\">
删除</a>\n";
echo "</td></tr>";
}
echo "</table>";
}
function createTable() {
global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $queryStr, $errMsg;
$queryStr = "CREATE TABLE ".$tablename;
mysql_select_db( $dbname, $mysqlHandle );
mysql_query( $queryStr, $mysqlHandle );
$errMsg = mysql_error();
listTables();
}
function dropTable() {
global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $queryStr, $errMsg;
$queryStr = "DROP TABLE $tablename";
mysql_select_db( $dbname, $mysqlHandle );
mysql_query( $queryStr, $mysqlHandle );
$errMsg = mysql_error();
listTables();
}
function viewSchema() {
global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $queryStr, $errMsg;
echo "<h1>
表结构</h1>\n";
echo "<p class=location>$dbname > $tablename</p>\n";
echoQueryResult();
echo "<a href='$PHP_SELF?action=addField&dbname=$dbname&tablename=$tablename'>
所有字段</a> | \n";
echo "<a href='$PHP_SELF?action=viewData&dbname=$dbname&tablename=$tablename'>
显示数据</a>\n";
echo "<hr>\n";
$pResult = mysql_db_query( $dbname, "SHOW fields FROM $tablename" );
$num = mysql_num_rows( $pResult );
echo "<table cellspacing=1 cellpadding=5>\n";
echo "<tr>\n";
echo "<th>
字段名称</th>\n";
echo "<th>
字段类型</th>\n";
echo "<th>
可空</th>\n";
echo "<th>
主键</th>\n";
echo "<th>
缺省值</th>\n";
echo "<th>
备注</th>\n";
echo "<th colspan=2>
操作</th>\n";
echo "</tr>\n";
for( $i = 0; $i < $num; $i++ ) {
$field = mysql_fetch_array( $pResult );
echo "<tr>\n";
echo "<td>".$field[ "Field"]. "</td>\n";
echo "<td>".$field[ "Type"]. "</td>\n";
echo "<td>".$field[ "Null"]. "</td>\n";
echo "<td>".$field[ "Key"]. "</td>\n";
echo "<td>".$field[ "Default"]. "</td>\n";
echo "<td>".$field[ "Extra"]. "</td>\n";
$fieldname = $field[ "Field"];
echo "<td><a href='$PHP_SELF?action=editField&dbname=$dbname&tablename=$tablename&fieldname=$fieldname'>
编辑</a></td>\n";
echo "<td><a href='$PHP_SELF?action=dropField&dbname=$dbname&tablename=$tablename&fieldname=$fieldname' ";
echo "onClick=\"return confirm('Drop Field \'$fieldname\'?')\">
删除</a></td> ";
echo "</tr>\n";
}
echo "</table>\n";
}
function manageField( $cmd ) {
global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF;
if( $cmd == "add" )
echo "<h1>
添加字段</h1>\n";
else if( $cmd == "edit" ) {
echo "<h1>
编辑字段</h1>\n";
$pResult = mysql_db_query( $dbname, "SHOW fields FROM $tablename" );
$num = mysql_num_rows( $pResult );
for( $i = 0; $i < $num; $i++ ) {
$field = mysql_fetch_array( $pResult );
if( $field[ "Field"] == $fieldname ) {
$fieldtype = $field[ "Type"];
$fieldkey = $field[ "Key"];
$fieldextra = $field[ "Extra"];
$fieldnull = $field[ "Null"];
$fielddefault = $field[ "Default"];
break; } }
$type = strtok( $fieldtype, " (,)\n" );
if( strpos( $fieldtype, "(" ) ) {
$M = strtok( " (,)\n" );
if( strpos( $fieldtype, "," ) )
$D = strtok( " (,)\n" );
} }
echo "<p class=location>$dbname > $tablename</p>\n";
echo "<form action=$PHP_SELF>\n";
if( $cmd == "add" )
echo "<input type=hidden name=action value=addField_submit>\n";
else if( $cmd == "edit" ) {
echo "<input type=hidden name=action value=editField_submit>\n";
echo "<input type=hidden name=old_name value=$fieldname>\n";
}
echo "<input type=hidden name=dbname value=$dbname>\n";
echo "<input type=hidden name=tablename value=$tablename>\n";
echo "<h3>
字段名称</h3>\n";
echo "<input type=text name=name value=$fieldname><p>\n";
?>
<h3>
说明</h3>
<font size=2>
* `M'
表示最大显示长度.<br>
* `D'
用于浮点数字型,表示小数点后面的小数位数.<br>
</font><table><tr>
<th>
类型</th><th> M </th><th> D </th><th>无符号</th><th>使用零填充</th><th>二进制库</th>
</tr><tr>
<td><input type=radio name=type value="TINYINT"
<? if( $type == "tinyint" ) echo "checked";?>>TINYINT (-128 ~ 127)</td>
<td align=center>O</td>
<td> </td>
<td align=center>O</td>
<td align=center>O</td>
<td> </td> </tr><tr>
<td><input type=radio name=type value="SMALLINT"
<? if( $type == "smallint" ) echo "checked";?>>SMALLINT (-32768 ~ 32767)</td>
<td align=center>O</td>
<td> </td>
<td align=center>O</td>
<td align=center>O</td>
<td> </td> </tr><tr>
<td><input type=radio name=type value="MEDIUMINT"
<? if( $type == "mediumint" ) echo "checked";?>>MEDIUMINT (-8388608 ~ 8388607)</td>
<td align=center>O</td>
<td> </td>
<td align=center>O</td>
<td align=center>O</td>
<td> </td></tr><tr>
<td><input type=radio name=type value="INT"
<? if( $type == "int" ) echo "checked";?>>INT (-2147483648 ~ 2147483647)</td>
<td align=center>O</td>
<td> </td>
<td align=center>O</td>
<td align=center>O</td>
<td> </td></tr><tr>
<td><input type=radio name=type value="BIGINT"
<? if( $type == "bigint" ) echo "checked";?>>BIGINT (-9223372036854775808 ~ 9223372036854775807)</td>
<td align=center>O</td>
<td> </td>
<td align=center>O</td>
<td align=center>O</td>
<td> </td></tr><tr>
<td><input type=radio name=type value="FLOAT"
<? if( $type == "float" ) echo "checked";?>>FLOAT</td>
<td align=center>O</td>
<td align=center>O</td>
<td> </td>
<td align=center>O</td>
<td> </td></tr><tr>
<td><input type=radio name=type value="DOUBLE"
<? if( $type == "double" ) echo "checked";?>>DOUBLE</td>
<td align=center>O</td>
<td align=center>O</td>
<td> </td>
<td align=center>O</td>
<td> </td></tr><tr>
<td><input type=radio name=type value="DECIMAL"
<? if( $type == "decimal") echo "checked";?>>DECIMAL(NUMERIC)</td>
<td align=center>O</td>
<td align=center>O</td>
<td> </td>
<td align=center>O</td>
<td> </td></tr><tr>
<td><input type=radio name=type value="DATE"
<? if( $type == "date" ) echo "checked";?>>DATE (1000-01-01 ~ 9999-12-31, YYYY-MM-DD)</td>
<td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr>
<td><input type=radio name=type value="DATETIME"
<? if( $type == "datetime")
echo "checked";?>>DATETIME (1000-01-01 00:00:00 ~ 9999-12-31 23:59:59,YYYY-MM-DD HH:MM:SS)</td>
<td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr>
<td><input type=radio name=type value="TIMESTAMP"
<? if( $type == "timestamp" )
echo "checked";?>>TIMESTAMP (1970-01-01 00:00:00 ~ 2106..., YYYYMMDD[HH[MM[SS]]])</td>
<td align=center>O</td>
<td> </td><td> </td><td> </td><td> </td></tr><tr>
<td><input type=radio name=type value="TIME"
<? if( $type == "time" ) echo "checked";?>>TIME (-838:59:59 ~ 838:59:59, HH:MM:SS)</td>
<td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr>
<td><input type=radio name=type value="YEAR"
<? if( $type == "year" ) echo "checked";?>>YEAR (1901 ~ 2155, 0000, YYYY)</td>
<td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr>
<td><input type=radio name=type value="CHAR"
<? if( $type == "char" ) echo "checked";?>>CHAR</td>
<td align=center>O</td>
<td> </td><td> </td><td> </td><td align=center>O</td></tr><tr>
<td><input type=radio name=type value="VARCHAR"
<? if( $type == "varchar" ) echo "checked";?>>VARCHAR</td>
<td align=center>O</td>
<td> </td><td> </td><td> </td><td align=center>O</td></tr><tr>
<td><input type=radio name=type value="TINYTEXT"
<? if( $type == "tinytext" ) echo "checked";?>>TINYTEXT (0 ~ 255)</td>
<td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr>
<td><input type=radio name=type value="TEXT"
<? if( $type == "text" ) echo "checked";?>>TEXT (0 ~ 65535)</td>
<td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr>
<td><input type=radio name=type value="MEDIUMTEXT"
<? if( $type == "mediumtext" ) echo "checked";?>>MEDIUMTEXT (0 ~ 16777215)</td>
<td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr>
<td><input type=radio name=type value="LONGTEXT"
<? if( $type == "longtext" ) echo "checked";?>>LONGTEXT (0 ~ 4294967295)</td>
<td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr>
<td><input type=radio name=type value="TINYBLOB"
<? if( $type == "tinyblob" ) echo "checked";?>>TINYBLOB (0 ~ 255)</td>
<td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr>
<td><input type=radio name=type value="BLOB"
<? if( $type == "blob" ) echo "checked";?>>BLOB (0 ~ 65535)</td>
<td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr>
<td><input type=radio name=type value="MEDIUMBLOB"
<? if( $type == "mediumblob" ) echo "checked";?>>MEDIUMBLOB (0 ~ 16777215)</td>
<td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr>
<td><input type=radio name=type value="LONGBLOB"
<? if( $type == "longblob" ) echo "checked";?>>LONGBLOB (0 ~ 4294967295)</td>
<td> </td><td> </td><td> </td><td> </td><td> </td></tr></table><table>
<tr><th>M</th><th>D</th><th>
无符号</th><th>使用零填充</th><th>二进制库</th></tr><tr>
<td align=center><input type=text size=4 name=M
<? if( $M != "" ) echo "value=$M";?>></td>
<td align=center><input type=text size=4 name=D
<? if( $D != "" ) echo "value=$D";?>></td>
<td align=center><input type=checkbox name=unsigned value="UNSIGNED"
<? if( strpos( $fieldtype, "unsigned" ) ) echo "checked";?>></td>
<td align=center><input type=checkbox name=zerofill value="ZEROFILL"
<? if(strpos( $fieldtype, "zerofill" ) ) echo "checked";?>></td>
<td align=center><input type=checkbox name=binary value="BINARY"
<? if( strpos( $fieldtype, "binary" ) ) echo "checked";?>></td>
</tr></table>
<h3>
特征</h3>
<table>
<tr><th>
非空</th><th>缺省值</th><th>自动增量</th><th>主键</th></tr>
<tr>
<td align=center><input type=checkbox name=not_null value="NOT NULL"
<? if($fieldnull != "YES" ) echo "checked";?>></td>
<td align=center><input type=text name=default_value
<? if( $fielddefault!= "" ) echo "value=$fielddefault";?>></td>
<td align=center><input type=checkbox name=auto_increment value="AUTO_INCREMENT"
<? if( $fieldextra == "auto_increment" ) echo "checked";?>></td>
<td align=center><input type=checkbox name=primary_key value="PRIMARY KEY"
<? if( $fieldkey == "PRI" ) echo "checked";?>></td>
</tr></table>
<p>
<?
if( $cmd == "add" )
echo "<input type=submit value='
添加字段'>\n";
else if( $cmd == "edit" )
echo "<input type=submit value='
编辑字段'>\n";
echo "<input type=button value=
取消 onClick='history.back()'>\n";
echo "</form>\n";
}
function manageField_submit( $cmd ) {
global $mysqlHandle, $dbname, $tablename, $old_name, $name, $type, $PHP_SELF, $queryStr, $errMsg,
$M, $D, $unsigned, $zerofill, $binary, $not_null, $default_value, $auto_increment, $primary_key;
if( $cmd == "add" ) $queryStr = "ALTER TABLE $tablename ADD $name ";
else if( $cmd == "edit" )
$queryStr = "ALTER TABLE $tablename CHANGE $old_name $name ";
if( $M != "" )
if( $D != "" ) $queryStr .= "$type($M,$D) ";
else $queryStr .= "$type($M) ";
else $queryStr .= "$type ";
$queryStr .= "$unsigned $zerofill $binary ";
if( $default_value != "" ) $queryStr .= "DEFAULT '$default_value' ";
$queryStr .= "$not_null $auto_increment";
mysql_select_db( $dbname, $mysqlHandle );
mysql_query( $queryStr, $mysqlHandle );
$errMsg = mysql_error();
$keyChange = false;
$result = mysql_query( "SHOW KEYS FROM $tablename" );
$primary = "";
while( $row = mysql_fetch_array($result) )
if( $row[ "Key_name"] == "PRIMARY" ) {
if( $row[Column_name] == $name ) $keyChange = true;
else $primary .= ", $row[Column_name]";
}
if( $primary_key == "PRIMARY KEY" ) {
$primary .= ", $name";
$keyChange = !$keyChange;
}
$primary = substr( $primary, 2 );
if( $keyChange == true ) {
$q = "ALTER TABLE $tablename DROP PRIMARY KEY";
mysql_query( $q );
$queryStr .= "<br>\n" . $q;
$errMsg .= "<br>\n" . mysql_error();
$q = "ALTER TABLE $tablename ADD PRIMARY KEY( $primary )";
mysql_query( $q );
$queryStr .= "<br>\n" . $q;
$errMsg .= "<br>\n" . mysql_error();
}
viewSchema();
}
function dropField() {
global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF, $queryStr, $errMsg;
$queryStr = "ALTER TABLE $tablename DROP COLUMN $fieldname";
mysql_select_db( $dbname, $mysqlHandle );
mysql_query( $queryStr , $mysqlHandle );
$errMsg = mysql_error();
viewSchema();
}
function viewData( $queryStr ) {
global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $errMsg;
echo "<h1>
数据库表中的数据</h1>\n";
if( $tablename != "" ) echo "<p class=location>$dbname >$tablename</p>\n";
else echo "<p class=location>$dbname</p>\n";
echoQueryResult();
$queryStr = stripslashes( $queryStr );
if( $queryStr == "" ) {
$queryStr = "SELECT * FROM $tablename";
echo "<a href='$PHP_SELF?action=addData&dbname=$dbname&tablename=$tablename'>
添加数据</a> | \n";
echo "<a href='$PHP_SELF?action=viewSchema&dbname=$dbname&tablename=$tablename'>
结构</a>\n";
} else echo "Query : $queryStr<br>";
$pResult = mysql_db_query( $dbname, $queryStr );
$errMsg = mysql_error();
$GLOBALS[queryStr] = $queryStr;
echo "<hr>\n";
if( $errMsg != "" ) echoQueryResult();
if( $pResult == false ) return;
if( $pResult == 1 ) {
echo "<h2>
操作成功!</h2><p>";
return;
}
$row = mysql_num_rows( $pResult );
$col = mysql_num_fields( $pResult );
echo "<table cellspacing=1 cellpadding=2>\n";
echo "<tr>\n";
for( $i = 0; $i < $col; $i++ ) {
$field = mysql_fetch_field( $pResult, $i );
echo "<th>".$field->name. "</th>\n";
}
echo "<th colspan=2>
操作</th>\n";
echo "</tr>\n";
for( $i = 0; $i < $row; $i++ ) {
echo "<tr>\n";
$rowArray = mysql_fetch_row( $pResult );
$key = "";
for( $j = 0; $j < $col; $j++ ) {
$data = $rowArray[$j];
$field = mysql_fetch_field( $pResult, $j );
if( $field->primary_key == 1 )
$key .= "&" . $field->name . "=" . $data;
if( strlen( $data ) > 20 )
$data = substr( $data, 0, 20 ) . "...";
$data = htmlspecialchars( $data );
echo "<td>\n";
echo "$data\n";
echo "</td>\n";
}
if( $key == "" ) echo "<td colspan=2>
没有主键</td>\n";
else {
echo "<td><a href='$PHP_SELF?action=editData&dbname=$dbname&tablename=$tablename$key'>
编辑</a></td>\n";
echo "<td><a href='$PHP_SELF?action=deleteData&dbname=$dbname&tablename=$tablename$key' ";
echo "onClick=\"return confirm('Delete Row?')\">
删除</a></td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
}
function manageData( $cmd ) {
global $mysqlHandle, $dbname, $tablename, $PHP_SELF;
if( $cmd == "add" )
echo "<h1>
添加数据</h1>\n";
else if( $cmd == "edit" ) {
echo "<h1>
编辑数据</h1>\n";
$pResult = mysql_list_fields( $dbname, $tablename );
$num = mysql_num_fields( $pResult );
$key = "";
for( $i = 0; $i < $num; $i++ ) {
$field = mysql_fetch_field( $pResult, $i );
if( $field->primary_key == 1 )
if( $field->numeric == 1 )
$key .= $field->name."=".$GLOBALS[$field->name]." AND ";
else
$key .= $field->name."='".$GLOBALS[$field->name]."' AND ";
}
$key = substr( $key, 0, strlen($key)-4 );
mysql_select_db( $dbname, $mysqlHandle );
$pResult = mysql_query( $queryStr = "SELECT * FROM $tablename WHERE $key", $mysqlHandle );
$data = mysql_fetch_array( $pResult );
}
echo "<p class=location>$dbname > $tablename</p>\n";
echo "<form action='$PHP_SELF' method=post>\n";
if($cmd=="add")echo "<input type=hidden name=action value=addData_submit>";
else if($cmd=="edit")
echo "<input type=hidden name=action value=editData_submit>";
echo "<input type=hidden name=dbname value=$dbname>\n";
echo "<input type=hidden name=tablename value=$tablename>\n";
echo "<table cellspacing=1 cellpadding=2>\n";
echo "<tr>\n";
echo "<th>
字段名称</th>\n";
echo "<th>
字段类型</th>\n";
echo "<th>
使用函数</th>\n";
echo "<th>
数据</th>\n";
echo "</tr>\n";
$pResult = mysql_db_query( $dbname,"SHOW fields FROM $tablename" );
$num = mysql_num_rows( $pResult );
$pResultLen = mysql_list_fields( $dbname, $tablename );
for( $i = 0; $i < $num; $i++ ) {
$field = mysql_fetch_array( $pResult );
$fieldname = $field[ "Field"];
$fieldtype = $field[ "Type"];
$len = mysql_field_len( $pResultLen, $i );
echo "<tr>";
echo "<td>$fieldname</td>";
echo "<td>".$field[ "Type"]. "</td>";
echo "<td>\n";
echo "<select name=${fieldname}_function>\n";
echo "<option><option>ASCII<option>CHAR<option>SOUNDEX\n";
echo "<option>CURDATE<option>CURTIME<option>FROM_DAYS\n";
echo "<option>FROM_UNIXTIME<option>NOW<option>PASSWORD\n";
echo "<option>PERIOD_ADD<option>PERIOD_DIFF<option>TO_DAYS\n";
echo "<option>USER<option>WEEKDAY<option>RAND</select>\n";
echo "</td>\n";
$value = htmlspecialchars($data[$i]);
if( $cmd == "add" ) {
$type = strtok( $fieldtype, " (,)\n" );
if( $type == "enum" || $type == "set" ) {
echo "<td>\n";
if( $type == "enum" ) echo "<select name=$fieldname>";
else if( $type == "set" )
echo "<select name=$fieldname size=4 multiple>\n";
echo strtok( "'" );
while( $str = strtok( "'" ) ) {
echo "<option>$str\n";
strtok( "'" );
}
echo "</select>\n";
echo "</td>\n";
} else {
if( $len < 40 )
echo "<td><input type=text size=40 maxlength=$len name=$fieldname></td>\n";
else
echo "<td><textarea cols=40 rows=3 maxlength=$len name=$fieldname></textarea>";
}
} else if( $cmd == "edit" ) {
if( $len < 40 )
echo "<td><input type=text size=40 maxlength=$len name=$fieldname value=$value></td>\n";
else
echo "<td><textarea cols=40 rows=3 maxlength=$len name=$fieldname>$value</textarea>\n";
}
echo "</tr>";
}
echo "</table><p>\n";
if( $cmd == "add" ) echo "<input type=submit value='
添加数据'>";
else if( $cmd == "edit" ) echo "<input type=submit value='
编辑数据'>";
echo "<input type=button value='
取消' onClick='history.back()'>\n";
echo "</form>\n";
}
function manageData_submit( $cmd ) {
global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF, $queryStr, $errMsg;
$pResult = mysql_list_fields( $dbname, $tablename );
$num = mysql_num_fields( $pResult );
mysql_select_db( $dbname, $mysqlHandle );
if( $cmd == "add" ) $queryStr = "INSERT INTO $tablename VALUES (";
else if( $cmd == "edit" ) $queryStr = "REPLACE INTO $tablename VALUES (";
for( $i = 0; $i < $num-1; $i++ ) {
$field = mysql_fetch_field( $pResult );
$func = $GLOBALS[$field->name. "_function"];
if( $func != "" ) $queryStr .= " $func(";
if( $field->numeric == 1 ) {
$queryStr .= $GLOBALS[$field->name];
if( $func != "" ) $queryStr .= "),";
else $queryStr .= ",";
} else {
$queryStr .= "'" . $GLOBALS[$field->name];
if( $func != "" ) $queryStr .= "'),";
else $queryStr .= "',";
}
}
$field = mysql_fetch_field( $pResult );
if( $field->numeric == 1 ) $queryStr .= $GLOBALS[$field->name] . ")";
else $queryStr .= "'" . $GLOBALS[$field->name] . "')";
mysql_query( $queryStr , $mysqlHandle );
$errMsg = mysql_error();
viewData( "" );
}
function deleteData() {
global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF, $queryStr, $errMsg;
$pResult = mysql_list_fields( $dbname, $tablename );
$num = mysql_num_fields( $pResult );
$key = "";
for( $i = 0; $i < $num; $i++ ) {
$field = mysql_fetch_field( $pResult, $i );
if( $field->primary_key == 1 )
if( $field->numeric == 1 )
$key .= $field->name."=".$GLOBALS[$field->name]."AND ";
else
$key .= $field->name."='".$GLOBALS[$field->name]."' AND ";
}
$key = substr( $key, 0, strlen($key)-4 );
mysql_select_db( $dbname, $mysqlHandle );
$queryStr = "DELETE FROM $tablename WHERE $key";
mysql_query( $queryStr, $mysqlHandle );
$errMsg = mysql_error();
viewData( "" );
}
function header_html() { global $PHP_SELF; ?>
<html><head><title>
数据库管理界面</title>
<style type="text/css">
<!--
p.location {
color: #11bb33;
font-size: small;
}
h1 {
color: #A4A260;
}
th {
background-color: #BDBE42;
color: #FFFFFF;
font-size: x-small;
}
td {
background-color: #DEDFA5;
font-size: x-small;
}
a{
text-decoration:none;
color: #848200;
font-size:x-small;
}
//-->
</style></head><body>
<?
}
function footer_html() {
global $mysqlHandle, $dbname, $tablename, $PHP_SELF;
?>
<hr>
<font size=2>
<a href=" <? echo "$PHP_SELF"; ?>?action=listDBs">
数据库列表</a> |
<?
if( $tablename != "" )
echo "<a href='$PHP_SELF?action=listTables&dbname=$dbname&tablename=$tablename'>
显示数据库表列表</a> | ";
?>
<a href=" <? echo "$PHP_SELF"; ?>?action=logout">
退出</a>
</font></body></html>
<?
}
if( $action == "logon" || $action == "" || $action == "logout" ) logon();
else if( $action == "logon_submit" ) logon_submit();
else {
while( list($var, $value) = each($HTTP_COOKIE_VARS) ) {
if( $var == "mysql_web_admin_username" ) $USERNAME = $value;
if( $var == "mysql_web_admin_password" ) $PASSWORD = $value;
}
$SERVER = "localhost";
$mysqlHandle = mysql_pconnect($SERVER, $USERNAME, $PASSWORD );
if( $mysqlHandle == false ) {
echo "<html><head><title>
管理员数据库管理界面</title></head>\n";
echo "<body>\n";
echo "<table width=100% height=100%><tr><td><center>\n";
echo "<h1>
输入错误,无法连接数据库!</h1>\n";
echo "<a href='$PHP_SELF?action=logon'>
退出</a>\n";
echo "</center></td></tr></table></body></html>";
} else {
header_html();
if( $action == "listDBs" ) listDatabases();
else if( $action == "createDB" ) createDatabase();
else if( $action == "dropDB" ) dropDatabase();
else if( $action == "listTables" ) listTables();
else if( $action == "createTable" ) createTable();
else if( $action == "dropTable" ) dropTable();
else if( $action == "viewSchema" ) viewSchema();
else if( $action == "query" ) viewData( $queryStr );
else if( $action == "addField" ) manageField( "add" );
else if( $action == "addField_submit" ) manageField_submit( "add" );
else if( $action == "editField" ) manageField( "edit" );
else if( $action == "editField_submit" ) manageField_submit( "edit" );
else if( $action == "dropField" ) dropField();
else if( $action == "viewData" ) viewData( "" );
else if( $action == "addData" ) manageData( "add" );
else if( $action == "addData_submit" ) manageData_submit( "add" );
else if( $action == "editData" ) manageData( "edit" );
else if( $action == "editData_submit" ) manageData_submit("edit");
else if( $action == "deleteData" ) deleteData();
footer_html();
} }
?>

 


(责任编辑:admin)
织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
推荐内容
  • 电池测试仪的几种测试模式

    判定电池健康状况的传统办法就是放电,通过放电来检测电池目前的实际容量,从而判定电...

  • 非热型放射性同位素电池

    而非热转换型放射性同位素电池则使用同位素衰变时放出的β粒子,也就是直接用电子来发...

  • 电池测试--电池巡检系统

    电池检测仪是一种针对电源系统蓄电池进行实时、完善的在线检测与管理的装置。目前已广...

  • 锂电池电量检测原理

    锂离子电池的大电流放电能力可通过使用较厚或较薄的活性材料层在很宽的范围内进行调整...

  • 如何降低动力电池成本

    从目前情况来看,动力电池技术有着长寿命、低成本、大负载、恶劣环境工作能力、高能量...

  • 物理电池的特性

    物理电池顾名思义,就是依靠物理变化来提供、储存电能的电池统称,如超级电容、飞轮电...