Introduction to the SQL Administrator's web interface

Source: Internet
Author: User
/*************************************************************************************
* Sqladmin V2.0-an SQL Administration User Interface for the Web *
* Copyright (C) 1997-98 Alessandro Vernet *
*************************************************************************************
* This library was 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 *
* Version 2 of the License, or (at your option) any later version. *
* *
* This library was distributed in the hope that it'll be useful, *
* 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. *
* *
* You should has received a copy of the GNU Library general public *
* License along with this library; If not, write to the *
* Free Software Foundation, Inc., Temple place-suite 330, *
* Boston, MA 02111-1307, USA. *
*************************************************************************************/


/* 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.
*-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
* Won't is 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);
$result = Ereg_replace ("<", "<", $result);
$result = ereg_replace (">", ">", $result);
return $result;
}

function Displaytuple ($fieldsNumber, $fieldNames,
$fieldLengths, $values, $mode)
{
$result = "";
$result. = "";
return $result;
}

function Fieldfromtype ($text, $type)
{
if ($type = = "int" | | $type = = "UINT" | | $type = = "real")
{$result = $text;}
Else
{$result = "'". Addslashes ($text). "'"; }
return $result;
}

function Executemsql ($database, $command)
{
/*echo " " . $command. "";*/
mSQL ($database, $command);
}

function Handleremove ($database, $table, $fieldsNumber,
$fieldNames, $fieldLengths, $fieldTypes)
{
Global $remove;
if ($remove! = "")
{
$command = "DELETE from". $table. "WHERE";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldName = "old-". $fieldNames [$fieldIndex];
Global $ $fieldName;
$command. = $fieldNames [$fieldIndex]. "=" .
Fieldfromtype ($ $fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex! = $fieldsNumber-1)
{$command. = "and";}
$fieldIndex + +;
}
Executemsql ($database, $command);
}
}

function Handleupdate ($database, $table, $fieldsNumber,
$fieldNames, $fieldLengths, $fieldTypes)
{
Global $update;
if ($update! = "")
{
$command = "UPDATE". $table. "SET";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldName = $fieldNames [$fieldIndex];
Global $ $fieldName;
$command. = $fieldName. "=" .
Fieldfromtype ($ $fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex! = $fieldsNumber-1)
{$command. = ",";}
$fieldIndex + +;
}
$command. = "WHERE";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldName = "old-". $fieldNames [$fieldIndex];
Global $ $fieldName;
$command. = $fieldNames [$fieldIndex]. "=" .
Fieldfromtype ($ $fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex! = $fieldsNumber-1)
{$command. = "and";}
$fieldIndex + +;
}
Executemsql ($database, $command);
}
}

function Handleadd ($database, $table, $fieldsNumber,
$fieldNames, $fieldLengths, $fieldTypes)
{
Global $add;
if ($add! = "")
{
$command = "INSERT into". $table. " (";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$command. = $fieldNames [$fieldIndex];
if ($fieldIndex! = $fieldsNumber-1)
{$command. = ",";}
$fieldIndex + +;
}
$command. = ") VALUES (";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldName = $fieldNames [$fieldIndex];
Global $ $fieldName;
$command. = Fieldfromtype ($ $fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex! = $fieldsNumber-1)
{$command. = ",";}
$fieldIndex + +;
}
$command. = ")";
Executemsql ($database, $command);
}
}

function Displayremoveupdate ($database, $table, $sortColumn,
$fieldsNumber, $fieldNames, $fieldLengths)
{
$result = "";
if ($sortColumn! = "")
{$sortColumn = "ORDER by". $sortColumn; }
$msqlresult = mSQL ($database, "select * from". $table. $sortColumn);
$tuplesNumber = Msql_numrows ($msqlresult);
$tupleIndex = 0;
while ($tupleIndex < $tuplesNumber)
{
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$values [$fieldIndex] = Msql_result ($msqlresult, $tupleIndex,
$fieldNames [$fieldIndex]);
$fieldIndex + +;
}
$result. = Displaytuple ($fieldsNumber, $fieldNames,
$fieldLengths, $values, "modify");
$tupleIndex + +;
}
return $result;
}

function Displayadd ($fieldsNumber, $fieldNames, $fieldLengths)
{
$result = "";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$values [$fieldIndex] = "";
$fieldIndex + +;
}
$result. = Displaytuple ($fieldsNumber, $fieldNames,
$fieldLengths, $values, "add");
Msql_close ();
return $result;
}

function administrationtable ($database, $table, $sortColumn)
{
$result = "";
Msql_connect ("localhost");
$msqlresult = mSQL ($database, "select * from". $table);
$fieldsNumber = Msql_numfields ($msqlresult);
$msqlresult = Msql_listfields ($database, $table);
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldNames [$fieldIndex] = Msql_fieldname ($msqlresult, $fieldIndex);
$fieldLengths [$fieldIndex] = Msql_fieldlen ($msqlresult, $fieldIndex);
$fieldTypes [$fieldIndex] = Msql_fieldtype ($msqlresult, $fieldIndex);
$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,
$fieldLengths);
$result. = Displayadd ($fieldsNumber, $fieldNames, $fieldLengths);
return $result;
}

function addtable ($database, $table)
{
$result = "";
Msql_connect ("localhost");
$msqlresult = mSQL ($database, "select * from". $table);
$fieldsNumber = Msql_numfields ($msqlresult);
$msqlresult = Msql_listfields ($database, $table);
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldNames [$fieldIndex] = Msql_fieldname ($msqlresult, $fieldIndex);
$fieldLengths [$fieldIndex] = Msql_fieldlen ($msqlresult, $fieldIndex);
$fieldTypes [$fieldIndex] = Msql_fieldtype ($msqlresult, $fieldIndex);
$fieldIndex + +;
}
Handleadd ($database, $table, $fieldsNumber, $fieldNames, $fieldLengths, $fieldTypes);
$result. = Displayadd ($fieldsNumber, $fieldNames, $fieldLengths);
return $result;
}
?>

The above describes the SQL Administrator's Web interface, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.