您好,欢迎访问一九零五行业门户网

SQL管理员的web接口介绍

/*************************************************************************************  
     *        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  .=    .  $fieldnames  [$fieldindex]  .   ;   
            if  ($fieldlengths  [$fieldindex]              {   
                $result  .=                      $fieldnames  [$fieldindex]  .  \  value=\  .   
                    $values  [$fieldindex]  .  \  size=\64\>;   
            }   
            else   
            {   
                $result  .=                      $fieldnames  [$fieldindex]  .  \  .   
                      cols=\64\  rows=\10\  wrap=\virtual\>  .   
                    escapeforhtml  ($values  [$fieldindex])  .  ;   
            }   
            $result  .=                    $fieldnames  [$fieldindex]  .   
                \  value=\  .  escapeforhtml  ($values  [$fieldindex])  .  \>  .
;   
            $fieldindex++;   
        }   
        $result  .=  ;   
        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;   
    }   
?>    以上就介绍了sql管理员的web接口介绍,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
其它类似信息

推荐信息