一个SQL管理员的web接口
时间:2008-05-29 来源:剑心通明
以下为引用的内容:
*
www.phperz.com
*************************************************************************************
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either * phperz~com
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, * phperz.com
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Library General Public License for more details. *
* * php程序员之家
* You should have received a copy of the GNU Library General Public *
* License along with this library; if not, write to the *
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, *
* Boston, MA 02111-1307, USA. *
www~phperz~com
*************************************************************************************/
/* TODO:
* - Add sort order.
* - Add simple view.
* - Add some documentation.
*/
/* LIMITATIONS:
* - Works only with mSQL.
*/
/* HISTORY:
* - 97-11-05 (avernet) Corrected a bug with quote.
php程序员站
* - 98-01-01 (avernet) Added a sortColumn parameter to
* administrationTable function.
* - 98-03-14 (avernet) Added function addTable to enable users to
* add (but not modify) en entry to the database.
* - 98-05-19 (avernet) Submitted to PX.
* - 98-10-11 (avernet) Now SQLAdmin works with PHP3. The PHP2 version
www~phperz~com
* will not be mainteained anymore.
* - 98-10-11 (avernet) SQLAdmin is now distributed under the LGPL
* instead of MPL.
*/
function escapeforhtml ($string)
{
$result = $string;
//$result = ereg_replace ("\"", """, $result); www~phperz~com
$result = ereg_replace ("", ">", $result);
return $result;
}
function displayTuple ($fieldsNumber, $fieldNames,
$fieldLengths, $values, $mode) php程序员站
{
$result = "";
$result .= "" .
"";
$result .= "";
$fieldIndex = 0;
while ($fieldIndex " . $fieldNames [$fieldIndex] . "";
if ($fieldLengths [$fieldIndex] php程序员站
$values [$fieldIndex] . "\" SIZE=\"64\">";
}
else
{
$result .= "" .
www.phperz.com
escapeforhtml ($values [$fieldIndex]) . "";
}
$result .= "" .
php程序员站
"";
$fieldIndex++;
}
$result .= "";
if ($mode == "modify")
{
$result .= ""; phperz.com
$result .= "";
}
else
{ $result .= ""; }
$result .= "";
return $result;
} phperz.com
function fieldFromType ($text, $type)
{
if ($type == "int" || $type == "uint" || $type == "real")
{ $result = $text; }
else
{ $result = "'" . AddSlashes ($text) . "'"; }
return $result; phperz~com
}
function executeMsql ($database, $command)
{
/*echo "" . $command . "";*/
msql ($database, $command);
}
function handleRemove ($database, $table, $fieldsNumber,
$fieldNames, $fieldLengths, $fieldTypes) www~phperz~com
{
global $remove;
if ($remove != "")
{
$command = "DELETE FROM " . $table . " WHERE ";
$fieldIndex = 0;
while ($fieldIndex phperz~com
global $$fieldName;
$command .= $fieldNames [$fieldIndex] . "=" .
fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= " AND "; } www.phperz.com
$fieldIndex++;
}
executeMsql ($database, $command);
}
}
function handleUpdate ($database, $table, $fieldsNumber,
$fieldNames, $fieldLengths, $fieldTypes)
www.phperz.com
{
global $update;
if ($update != "")
{
$command = "UPDATE " . $table . " SET ";
$fieldIndex = 0;
while ($fieldIndex phperz.com
global $$fieldName;
$command .= $fieldName . "=" .
fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= ", "; }
php程序员之家
$fieldIndex++;
}
$command .= " WHERE ";
$fieldIndex = 0;
while ($fieldIndex php程序员之家
global $$fieldName;
$command .= $fieldNames [$fieldIndex] . "=" .
fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= " AND "; } php程序员之家
$fieldIndex++;
}
executeMsql ($database, $command);
}
}
function handleAdd ($database, $table, $fieldsNumber,
$fieldNames, $fieldLengths, $fieldTypes)
{
php程序员站
global $add;
if ($add != "")
{
$command = "INSERT INTO " . $table . " (";
$fieldIndex = 0;
while ($fieldIndex www.phperz.com
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= ", "; }
$fieldIndex++;
}
$command .= ") VALUES (";
$fieldIndex = 0;
while ($fieldIndex phperz~com
{
$fieldName = $fieldNames [$fieldIndex];
global $$fieldName;
$command .= fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= ", "; } www~phperz~com
$fieldIndex++;
}
$command .= ")";
executeMsql ($database, $command);
}
}
function displayRemoveUpdate ($database, $table, $sortColumn,
$fieldsNumber, $fieldNames, $fieldLengths)
php程序员之家
{
$result = "";
if ($sortColumn != "")
{ $sortColumn = " ORDER BY " . $sortColumn; }
$msqlresult = msql ($database, "SELECT * FROM " . $table . $sortColumn);
$tuplesNumber = msql_numrows ($msqlresult);
$tupleIndex = 0;
phperz.com
while ($tupleIndex php程序员站
$fieldIndex++;
}
$result .= displayTuple ($fieldsNumber, $fieldNames,
$fieldLengths, $values, "modify");
$tupleIndex++;
}
return $result;
}
function displayAdd ($fieldsNumber, $fieldNames, $fieldLengths) www.phperz.com
{
$result = "";
$fieldIndex = 0;
while ($fieldIndex www.phperz.com
msql_close ();
return $result;
}
function administrationTable ($database, $table, $sortColumn)
{
$result = "";
msql_connect ( "localhost");
$msqlresult = msql ($database, "SELECT * FROM " . $table);
$fieldsNumber = msql_numfields ($msqlresult); phperz.com
$msqlresult = msql_listfields ($database, $table);
$fieldIndex = 0;
while ($fieldIndex www.phperz.com
$fieldIndex++;
}
handleRemove ($database, $table, $fieldsNumber, $fieldNames, $fieldLengths, $fieldTypes);
handleUpdate ($database, $table, $fieldsNumber, $fieldNames, $fieldLengths, $fieldTypes);
handleAdd ($database, $table, $fieldsNumber, $fieldNames, $fieldLengths, $fieldTypes);
$result .= displayRemoveUpdate ($database, $table, $sortColumn, $fieldsNumber, $fieldNames, php程序员站
$fieldLengths);
$result .= displayAdd ($fieldsNumber, $fieldNames, $fieldLengths);
return $result;
}
function addTable ($database, $table)
{
$result = "";
msql_connect ( "localhost");
$msqlresult = msql ($database, "SELECT * FROM " . $table); php程序员站
$fieldsNumber = msql_numfields ($msqlresult);
$msqlresult = msql_listfields ($database, $table);
$fieldIndex = 0;
while ($fieldIndex
*
www.phperz.com
*************************************************************************************
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either * phperz~com
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, * phperz.com
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Library General Public License for more details. *
* * php程序员之家
* You should have received a copy of the GNU Library General Public *
* License along with this library; if not, write to the *
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, *
* Boston, MA 02111-1307, USA. *
www~phperz~com
*************************************************************************************/
/* TODO:
* - Add sort order.
* - Add simple view.
* - Add some documentation.
*/
/* LIMITATIONS:
* - Works only with mSQL.
*/
/* HISTORY:
* - 97-11-05 (avernet) Corrected a bug with quote.
php程序员站
* - 98-01-01 (avernet) Added a sortColumn parameter to
* administrationTable function.
* - 98-03-14 (avernet) Added function addTable to enable users to
* add (but not modify) en entry to the database.
* - 98-05-19 (avernet) Submitted to PX.
* - 98-10-11 (avernet) Now SQLAdmin works with PHP3. The PHP2 version
www~phperz~com
* will not be mainteained anymore.
* - 98-10-11 (avernet) SQLAdmin is now distributed under the LGPL
* instead of MPL.
*/
function escapeforhtml ($string)
{
$result = $string;
//$result = ereg_replace ("\"", """, $result); www~phperz~com
$result = ereg_replace ("", ">", $result);
return $result;
}
function displayTuple ($fieldsNumber, $fieldNames,
$fieldLengths, $values, $mode) php程序员站
{
$result = "";
$result .= "" .
"";
$result .= "";
$fieldIndex = 0;
while ($fieldIndex " . $fieldNames [$fieldIndex] . "";
if ($fieldLengths [$fieldIndex] php程序员站
$values [$fieldIndex] . "\" SIZE=\"64\">";
}
else
{
$result .= "" .
www.phperz.com
escapeforhtml ($values [$fieldIndex]) . "";
}
$result .= "" .
php程序员站
"";
$fieldIndex++;
}
$result .= "";
if ($mode == "modify")
{
$result .= ""; phperz.com
$result .= "";
}
else
{ $result .= ""; }
$result .= "";
return $result;
} phperz.com
function fieldFromType ($text, $type)
{
if ($type == "int" || $type == "uint" || $type == "real")
{ $result = $text; }
else
{ $result = "'" . AddSlashes ($text) . "'"; }
return $result; phperz~com
}
function executeMsql ($database, $command)
{
/*echo "" . $command . "";*/
msql ($database, $command);
}
function handleRemove ($database, $table, $fieldsNumber,
$fieldNames, $fieldLengths, $fieldTypes) www~phperz~com
{
global $remove;
if ($remove != "")
{
$command = "DELETE FROM " . $table . " WHERE ";
$fieldIndex = 0;
while ($fieldIndex phperz~com
global $$fieldName;
$command .= $fieldNames [$fieldIndex] . "=" .
fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= " AND "; } www.phperz.com
$fieldIndex++;
}
executeMsql ($database, $command);
}
}
function handleUpdate ($database, $table, $fieldsNumber,
$fieldNames, $fieldLengths, $fieldTypes)
www.phperz.com
{
global $update;
if ($update != "")
{
$command = "UPDATE " . $table . " SET ";
$fieldIndex = 0;
while ($fieldIndex phperz.com
global $$fieldName;
$command .= $fieldName . "=" .
fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= ", "; }
php程序员之家
$fieldIndex++;
}
$command .= " WHERE ";
$fieldIndex = 0;
while ($fieldIndex php程序员之家
global $$fieldName;
$command .= $fieldNames [$fieldIndex] . "=" .
fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= " AND "; } php程序员之家
$fieldIndex++;
}
executeMsql ($database, $command);
}
}
function handleAdd ($database, $table, $fieldsNumber,
$fieldNames, $fieldLengths, $fieldTypes)
{
php程序员站
global $add;
if ($add != "")
{
$command = "INSERT INTO " . $table . " (";
$fieldIndex = 0;
while ($fieldIndex www.phperz.com
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= ", "; }
$fieldIndex++;
}
$command .= ") VALUES (";
$fieldIndex = 0;
while ($fieldIndex phperz~com
{
$fieldName = $fieldNames [$fieldIndex];
global $$fieldName;
$command .= fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= ", "; } www~phperz~com
$fieldIndex++;
}
$command .= ")";
executeMsql ($database, $command);
}
}
function displayRemoveUpdate ($database, $table, $sortColumn,
$fieldsNumber, $fieldNames, $fieldLengths)
php程序员之家
{
$result = "";
if ($sortColumn != "")
{ $sortColumn = " ORDER BY " . $sortColumn; }
$msqlresult = msql ($database, "SELECT * FROM " . $table . $sortColumn);
$tuplesNumber = msql_numrows ($msqlresult);
$tupleIndex = 0;
phperz.com
while ($tupleIndex php程序员站
$fieldIndex++;
}
$result .= displayTuple ($fieldsNumber, $fieldNames,
$fieldLengths, $values, "modify");
$tupleIndex++;
}
return $result;
}
function displayAdd ($fieldsNumber, $fieldNames, $fieldLengths) www.phperz.com
{
$result = "";
$fieldIndex = 0;
while ($fieldIndex www.phperz.com
msql_close ();
return $result;
}
function administrationTable ($database, $table, $sortColumn)
{
$result = "";
msql_connect ( "localhost");
$msqlresult = msql ($database, "SELECT * FROM " . $table);
$fieldsNumber = msql_numfields ($msqlresult); phperz.com
$msqlresult = msql_listfields ($database, $table);
$fieldIndex = 0;
while ($fieldIndex www.phperz.com
$fieldIndex++;
}
handleRemove ($database, $table, $fieldsNumber, $fieldNames, $fieldLengths, $fieldTypes);
handleUpdate ($database, $table, $fieldsNumber, $fieldNames, $fieldLengths, $fieldTypes);
handleAdd ($database, $table, $fieldsNumber, $fieldNames, $fieldLengths, $fieldTypes);
$result .= displayRemoveUpdate ($database, $table, $sortColumn, $fieldsNumber, $fieldNames, php程序员站
$fieldLengths);
$result .= displayAdd ($fieldsNumber, $fieldNames, $fieldLengths);
return $result;
}
function addTable ($database, $table)
{
$result = "";
msql_connect ( "localhost");
$msqlresult = msql ($database, "SELECT * FROM " . $table); php程序员站
$fieldsNumber = msql_numfields ($msqlresult);
$msqlresult = msql_listfields ($database, $table);
$fieldIndex = 0;
while ($fieldIndex
相关阅读 更多 +