search
HomeBackend DevelopmentPHP Tutorial一个SQL管理员的web接口_php基础

   
    /*************************************************************************************  
     *        SQLAdmin  v2.0  -  An  SQL  Administration  User  Interface  for  the  Web *   
     *            Copyright  (C)  1997-98    Alessandro  Vernet        *   
     *************************************************************************************   
     *      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         *   
     *      version  2  of  the  License,  or  (at  your  option)  any  later  version.  *   
     *                                                                                   *   
     *      This  library  is  distributed  in  the  hope  that  it  will  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  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.                                             *   
     *************************************************************************************/   


    /*  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   
      *      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);   
        $result  =  ereg_replace  ("        $result  =  ereg_replace  (">",  ">",  $result);   
        return  $result;   
    }   

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

"  .   
            "
";   
        $result  .=  "";   
        $fieldIndex  =  0;   
        while  ($fieldIndex          {   
            $result  .=  "";   
            $fieldIndex++;   
        }   
        $result  .=  "
"  .  $fieldNames  [$fieldIndex]  .  " ";   
            if  ($fieldLengths  [$fieldIndex]              {   
                $result  .=  "                    $fieldNames  [$fieldIndex]  .  "\"  VALUE=\""  .   
                    $values  [$fieldIndex]  .  "\"  SIZE=\"64\">";   
            }   
            else   
            {   
                $result  .=  "";   
            }   
            $result  .=    "                $fieldNames  [$fieldIndex]  .   
                "\"  VALUE=\""  .  escapeforhtml  ($values  [$fieldIndex])  .  "\">"  .   
                "
";   
        if  ($mode  ==  "modify")   
        {   
            $result  .=  "";   
            $result  .=  "";   
        }   
        else   
            {  $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              {   
                $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              {   
                $fieldName  =  $fieldNames  [$fieldIndex];   
                global  $$fieldName;   
                $command  .=  $fieldName  .  "="  .   
                    fieldFromType  ($$fieldName,  $fieldTypes  [$fieldIndex]);   
                if  ($fieldIndex  !=  $fieldsNumber  -  1)   
                    {  $command  .=  ",  ";  }   
                $fieldIndex++;   
            }   
            $command  .=  "  WHERE  ";   
            $fieldIndex  =  0;   
            while  ($fieldIndex              {   
                $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              {   
                $command  .=  $fieldNames  [$fieldIndex];   
                if  ($fieldIndex  !=  $fieldsNumber  -  1)   
                    {  $command  .=  ",  ";  }   
                $fieldIndex++;   
            }   
            $command  .=  ")  VALUES  (";   
            $fieldIndex  =  0;   
            while  ($fieldIndex              {   
                $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          {   
            $fieldIndex  =  0;   
            while  ($fieldIndex              {   
                $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          {   
            $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          {   
            $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          {   
            $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;   
    }   
?>   

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Explain the concept of late static binding in PHP.Explain the concept of late static binding in PHP.Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

PHP Logging: Best Practices for PHP Log AnalysisPHP Logging: Best Practices for PHP Log AnalysisMar 10, 2025 pm 02:32 PM

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Discover File Downloads in Laravel with Storage::downloadDiscover File Downloads in Laravel with Storage::downloadMar 06, 2025 am 02:22 AM

The Storage::download method of the Laravel framework provides a concise API for safely handling file downloads while managing abstractions of file storage. Here is an example of using Storage::download() in the example controller:

HTTP Method Verification in LaravelHTTP Method Verification in LaravelMar 05, 2025 pm 04:14 PM

Laravel simplifies HTTP verb handling in incoming requests, streamlining diverse operation management within your applications. The method() and isMethod() methods efficiently identify and validate request types. This feature is crucial for building

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version