  PHP Ͽ

  Al Dev (Alavoor Vasudevan)            alavoor@yahoo.com
  v8.0, 26 Sep 2000
  ȣ(KwangHo, Yun),       airplanez@kldp.org
  PHP-HOWTO_kr.sgml, v0.01 2000/11/07 15:50

  ̹  PHP α׷  Windows 95 GUI
  ø̼ Ǹ PHP + HTML + DHTML + XML + Java applets +
  Javascript  ٲٴ  Ұ̴.  ̹ ִ  PHP
   Ǿִ Linux, Windows 95/NT, OS/2, Unix 迭 Solaris, HPUX,
  AIX, SCO, Sinix, BSD,  ü迡 ȴ.
  ______________________________________________________________________

  

  1. Ұ
  2. PHP ޱAID CDATA PHP Download(LABEL)LABEL
     2.1 Microsoft Windows 95/98/NT/2000 PHP ġAID CDATA PHP Installation(LABEL)LABEL
     2.2 н ٸ ÷ PHP ġAID CDATA PHP Installation(LABEL)LABEL

  3. PHP Ʃ丮 AID CDATA PHP Tutorial(LABEL)LABEL
  4. PHP  IDE(ȯ)  AID CDATA PHP IDE(LABEL)LABEL
  5.  !!! PHP  ctags ! AID CDATA ptags(LABEL)LABEL
  6. PHP  AID CDATA debugphp(LABEL)LABEL
  7. PHP 
  8. ִ  URL
  9. ̹ ٸ 
  10. ۱
  11. η A Database Wrapper  AID CDATA Appendix A(LABEL)LABEL
  12. η B SQL abstraction Example AID CDATA Appendix B(LABEL)LABEL
  13. η C PostgreSQL large object  AID CDATA Appendix C(LABEL)LABEL
  14. η D    AID CDATA Appendix D(LABEL)LABEL
  15. η E Ʈũ   AID CDATA Appendix E(LABEL)LABEL
  16. η F PostgreSQL Database Wrapper  AID CDATA Appendix F(LABEL)LABEL
  17. η G Microsoft SQL Server DB Wrapper  AID CDATA mssql G(LABEL)LABEL
  18. η H Sybase SQL Server DB Wrapper  AID CDATA sybase H(LABEL)LABEL
  19. η I phpDB.inc  AID CDATA phpdb I(LABEL)LABEL
  20. η J phpDBTest.php3  AID CDATA phpDBTest(LABEL)LABEL

  ______________________________________________________________________

  1.  Ұ

  PHP  'Hypertext Pre-Processor' ǹϰ ̵(server side)
  HTML ũ/α׷ ̴.  PHP   
  ְش. PHP   Ϲ HTML ó ޵Ǹ 
  HTML ó   Ҽ ִ.

   ȸ PHP "߿亸Ȱ  " Ҽ ִ ǻ
   , ׷  ߾˷  ̴ , ͳ,
  ڻŷ B2B(business-to-business) Ʈ  ũƮ 
  Ǿ.  ׷ ұϰ   ȸ PHP ȿ
  ؼ ʴٰ Ѵ(ڵ).(:  ̻ϳ..)

  PHP 迡 ǳ ų ̸ IT踦  ϰ
  ɰ̴!!  PHP Ŀ ũν-÷ ̰  ȴ!!
  PHP ,  95/98/NT,  2000, ֶ󸮽, HPUX  н
  迭 ȴ. PHP ѹۼ Ǹ 𼭳 ȴ.  PHP
  ġ, ũμƮ IIS    ȴ.

  PHP ڹٺ 5 20 !! PHP ϴµ ô, ſ
   /ڻŷ ø̼ ſ  ª ð Ҽ
  ִ.

  PHP ü Ư¡ ڹ, C++, PERL "C"  Ǹ Ư¡
  Դ.  PHP ڹ, C++, PERL C Ǹ Ư¡ ü̴.

  PHP  ũƮ/α׷   ̸  
  α׷ "ī" ɰ̴!!  PHP  95/NT   н
  Ǳ  Ŵ    .

  PHP   ǵ Ƽ(Zend Optimizer) Ͽ
  ϰ ȭ(optimized)ų ִ. Ƽ(Zend Optimizer)
  PHP  4.0  PHP յǾ.

   ڻŷ(e-commerce) Ʈ ϴµ  PHP (70% ڵ) +
  HTML/DHTML/XML (25% ڵ) + Javascript (5% ڵ Ŭ̾Ʈ ) 
   Ұ̴.

  2.  PHP ޱ

  o  PHP  Ʈ  <http://www.php.net>

  o  PHP ҽ  <http://ils.unc.edu/web-db/php/links.html>

  o  PHP ڵ ȯ -  <http://px.sklar.com>

  2.1.  Microsoft Windows 95/98/NT/2000 PHP ġ

  PHP Microsoft Windows ÷ ſ αְ Ե MS  ASP
  ƮƮ   αִ!!  PHP ū  MS  ,
  н Ҽ ְ ݴ Ҽ ִٴ ̴!!

  MS  98/NT/2000  PHP 䰡   డ
  ġα׷ غǾ ִ.   ȭ Ŭ ϴ ͸
  2и PHPġ ڵ ̷.  డ ġȭ
  ٿε϶.

  o  MS Windows PHP ġ α׷
     <http://php.weblogs.com/easywindows>

  o    ÷ PHP   <http://php.weblogs.com>

  2.2.  н ٸ ÷ PHP ġ

  PHP λƮ <http://www.php.net>  ٿε Ű ġ
   ġ̵ ø .

  3.  PHP Ʃ丮

  ⿡   PHP  ϰ .php3   ȭ
  PHP  ȴٰ Ѵ.

  ù° PHP  :   ־ hello.php3 ȭ
  :

  ______________________________________________________________________
        <html>< head>< title >PHP Test< /title >< /head >
        < body>
        <?php echo "Hello World<P>"; ?>
        < /body>< /html>
  ______________________________________________________________________

  CGI ũƮ ó  ̴.  Ư ±׸  ִ 
  HTML ó ϶.
   ̰ ߴµ ƹ  Ÿ , PHP 
   ̴.   ڿ ǰ شް û϶.

  ̹  PHP Ư ±׸ ֱ Ѱ ̴. ̹
   츮 PHP ±  ˸ < ?php Ͽ. ׸
  PHP  ְ ? > ±׸  ־.    HTML ȭ
  ϴ  ̷ μ PHP 带 ϰ  ִ.

  츮      ϴ ˻غ̴.
  ׷ ϱ 츮   û  κ üũѴ.
     ȴ.   ޷($) Ѵ.
  츮    $HTTP_USER_AGENT ̴. ̰ ֱ
  ؼ 츮   Ҽ ִ:

  ______________________________________________________________________
        <?php echo $HTTP_USER_AGENT; ?>
  ______________________________________________________________________

        ϴ , ̷
  ´:

  Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)

  ڽ   ڵ Ǵ  ٸ  ִ.
    ȭ μ   Ʈ  ִ:

  ______________________________________________________________________
        <?php phpinfo()?>
  ______________________________________________________________________

   ȭ о̸ ڽѵ    Ʈ
  ȭ鰡     ̴.

  PHP ±׾ȿ  PHP    ϳ̻ echo
    ڵ  ִ.

  ______________________________________________________________________
        <?php
        if(strstr($HTTP_USER_AGENT,"MSIE")) {
            echo "You are using Internet Explorer<br>";
        }
        ?>
  ______________________________________________________________________

  ⿡ PHP  ߰ PHP带  
  ̴ٰ:

  ______________________________________________________________________
          <?php
          if(strstr($HTTP_USER_AGENT,"MSIE"))
          {
                  ?>
                  < center>< b>You are using Internet Explorer< /b>< /center>
                  <?
          }
          else
          {
                  ?>
                  < center>< b>You are not using Internet Explorer< /b>< /center>
                  <?
          }
          ?>
  ______________________________________________________________________

  PHP echo  ϴ  PHP 带   HTML  
  ִ.  ⼭ Ϸ ϴ ߿ϰ    帧
   ʰ  ִٴ ̴.  HTML  ᱹ 
  Ը  Ǵ°̴.  ũƮ Ű  
   :

  You are using Internet Explorer

   ٷ

  PHP    ϳ HTML (form) ٷ ̴.
  װ ϴ ߿ ⺻     ҵ
  ڵ  ִ ̸   ڵ ٲ
  ҷ(target)   ȴٴ ̴. ϰ 鸱̴. ׷
     ִ.       ִٰ
  ϶ :

  ______________________________________________________________________
        <form action="action.php3" method="POST">
        Your name: <input type=text name=name>
        You age: <input type=text name=age>
        <input type=submit>
        < /form>
  ______________________________________________________________________

  ⿡ ִ   Ư ͵.  Ư ±׵ 
   HTML  Ұ ϴ. ڰ  Էϰ ۹ư 
  action.php3 ҷ.  ҷ ȭϿ   
  ̴:

  ______________________________________________________________________
        Hi <?php echo $name?>.  You are <?php echo $age?> years old.
  ______________________________________________________________________

  Ե $name $age  PHP  ڵ !!

  4.  PHP  IDE(ȯ) 

   HTML ͵ PHP Ѵ :

  o  Soyal Ǹ PHP   <http://soyal.free.fr/PHPEd>

  o  Blue Fish  <http://bluefish.linuxave.net>

  o  Coffee cup  <http://www.coffeecup.com/linux>

  o  帲(Dreamweaver)  <http://www.dreamweaver.com>

  o  Amaya  <http://www.w3.org/Amaya>

  o  Homesite  <http://www.allaire.com/homesite>

  o  Hotdog  <http://www.hotdog.com>

  o  Zend Optimizers(Ƽ)  <http://www.zend.com>

  o  Zend Compilers(Ϸ)  <http://www.zend.com>

  o  MS Windows ÷  PHP   <http://php.weblogs.com>

      Ͽ  HTML Ϳ XML Ͱ " ø̼
     "  PHP Ұ̴.  .

  5.   !!! PHP  ctags !

   ±׵  ߿ϰ vi, emacs, CRiSP, NEdit   ͷ
  ҽڵ带 Ž(˻)ϴµ .  C, C++ Ǵ ڹٷ
  α׷   ִٸ ±׸ ϱ  ctags α׷
  Ҽ ̴.  ¶ ޴ (online manual page)
  ؼ /н bash prompt  'man ctags' ġ ȴ.

  PHP  ptags α׷  ִ. װ ϸ PHP
  ҽڵ带  ±׸ Ҽ ִ. ptags ϸ  꼺
  3 4 ɰ̴.

    <http://metalab.unc.edu/LDP/HOWTO/Vim-HOWTO.html> ִ PHP, C,
  C++  Vim ÷ ؽƮ ͸ ϶.

  ______________________________________________________________________
  // ptags.cpp ȭ ϰ
  // g++ -o ptags ptags.cpp  ϶.
  //*****************************************************************
  // GNU/GPL ۱ . ߰ 縦 ϰԵǸ  ̸,
  // ̸ ԽѶ.
  //  : Al Dev Email: alavoor@yahoo.com
  // Usage : ptags *.php3 *.inc
  //                 This will generate a file called tags
  //*****************************************************************
  #include <iostream.h>
  #include <fstream>
  #include <stdio.h> // for sprintf
  #include <stdlib.h> // for system
  #include <string.h> // for memset
  #include <ctype.h> // for isspace

  #define BUFF_LEN  1024
  #define LOCATION  9

  char *ltrim(char *dd);
  char *rtrim(char *ee);

  main(int argc, char **argv)
  {
          if (argc < 2)
          {
                  cerr << "\nUsage: " << argv[0] << " file .... " << endl;
                  exit(0);
          }

          char fname[100] = "tag_file.out";
          FILE    *fpout;
          ofstream    fout(fname);
          if (fout.fail())
          {
                  cerr << "\nError opening file : " << fname << endl;
                  exit(-1);
          }
          //fpout = fopen(fname, "w");

          for (int ii = 1; ii < argc; ii++)
          {
                  /*
                  char buff[2024];

                  sprintf(buff, "\\rm -f %s; ls %s > %s 2>/dev/null", outfile, argv[1], outfile);
                  cout << "\nbuff = " << buff << endl;

                  system(buff);
                  fclose(fp);
                  */
                  FILE *fpin = NULL;
                  fpin = fopen(argv[ii], "r");
                  if (fpin == NULL)
                  {
                          cerr << "\nError opening file : " << argv[ii] << endl;
                          exit(-1);
                  }
                  char buff[BUFF_LEN + 100];
                  memset(buff, 0, BUFF_LEN +10);
                  for ( ; fgets(buff, BUFF_LEN, fpin) != NULL; )
                  {
                          char aa[BUFF_LEN + 100];
                          memset(aa, 0, BUFF_LEN +10);
                          strcpy(aa, buff);
                          ltrim(aa);

                          // Remove the trailing new line..
                          {
                                  int tmpii = strlen(aa);
                                  if (aa[tmpii-1] == '\n')
                                          aa[tmpii-1] = 0;
                          }
                          //cout << "aa is : " << aa << endl;
                          if (strncmp(aa, "function ", LOCATION) != 0)
                                  continue;
                          //cout << buff << endl;

                          // Example tags file output is like -
                          // al2  al.c    /^al2()$/;"   f
                          {
                                  char bb[BUFF_LEN + 100];
                                  memset(bb, 0, BUFF_LEN +10);
                                  strcpy(bb, & aa[LOCATION]);
                                  char *cc = bb;
                                  while (cc != NULL && *cc != '(')
                                          *cc++;
                                  *cc = 0;
                                  cc = rtrim(bb);
                                  //cout << "bb is : " << bb << endl;
                                  //cout << cc << "\t" << argv[ii] << "\t" << "/^" << aa << "$/;\"\tf" << endl;
                                  fout << cc << "\t" << argv[ii] << "\t" << "/^" << aa << "$/;\"\tf" << endl;
                                  //fprintf(fpout, "%s\t%s\t/^%s$/;\"f\n", cc, argv[ii], aa );
                          }

                          memset(buff, 0, BUFF_LEN +10);
                  }
                  fclose(fpin);
          }
          fout.flush();
          fout.close();
          //fclose(fpout);

          // Sort and generate the tag file
          {
                  char tmpaa[1024];
                  sprintf(tmpaa, "sort %s > tags; \\rm -f %s", fname, fname);
                  system(tmpaa);
          }
  }

  char *ltrim(char *dd)
  {
      if (dd == NULL)
          return NULL;

      while (isspace(*dd))
          dd++;

          return dd;
  }

  char *rtrim(char *ee)
  {
      if (ee == NULL)
          return NULL;

          int tmpii = strlen(ee) - 1;
          for (; tmpii >= 0 ; tmpii--)
          {
                  if (isspace(ee[tmpii]) )
                  {
                          //cout << "\nis a space!!" << endl;
                          ee[tmpii] = 0;
                  }
          }
          return ee;
  }
  ______________________________________________________________________

  6.  PHP 

  PHP α׷  Ϸ  Լ  "debug2.inc"̶
  ȭ  :

  ______________________________________________________________________
  <?php

  /*  Ǵ  ϱ   */
  if (!defined("_DEBUG2_DEFINED_"))
  {
          define("_DEBUG2_DEFINED_", 1 );
  }
  else
          return; //  ȭ include ƴٸ 
  # file name : debug2.inc
  # PHP ҽ ڵ带 ϱ  Լ
  #*****************************************************************
  # Copyright policy is GNU/GPL but additional request is
  # that you include author's name and email on all copies
  # Author : Al Dev Email: alavoor@yahoo.com
  #*****************************************************************

  # Usage of this functions -
  # In your source code put something like -
  # debug2_(__FILE__, __LINE__, "f_somevariable", $f_somevariable);
  # And this will generate output in debug.out file.

  //function debug2_($fname, $lname, $debug_var, $debug_value=0) {}

  // Give read, exec for all on directory /debug2_logs
  // chmod a+rwx /debug2_logs
  // But here you need to open the file in append mode.
  $fp_debug2 = fopen("/debug2_logs/debug.out", "a");
  if ($fp_debug2 == false)
  {
          print "<b>File open failed - global.var.inc<b>";
          exit;
  }

  function debug2_($fname, $lname, $debug_var, $debug_value=0)
  {
          global $fp_debug2;

          //print "<br> debug_value is : $debug_value <br>";
          if (!$debug_value)
          {
                  fwrite($fp_debug2, "\n ". $fname ."  ". $lname .": $debug_var");
          }
          else
          {
                  fwrite($fp_debug2, "\n ". $fname . " ". $lname .": $debug_var = $debug_value");
          }
          //print "<br> f_cookie is : $f_cookie <br>";
  }

  // In your first page, which is generally index.php3
  // truncate the debug2_logs file in beginning of code
  function init_debug_file()
  {
          global $fp_debug2;

          $fp_debug2 = fopen("/debug2_logs/debug.out", "w");
          if ($fp_debug2 == false)
          {
                  print "<b>File open failed - global.var.inc<b>";
                  exit;
          }
          system("chmod a+rwx /debug2_logs/debug.out");
  }

  ?>
  ______________________________________________________________________

   index.php3 Ǵ  PHP ҽڵ忡  ־.

  ______________________________________________________________________
  <?php
          include ("debug2.inc");

          init_debug_file();
          // ٸ  ⿡.....
          // ...........
  ?>
  ______________________________________________________________________

     PHP ҽڵ Ͽ debug2_()  ȣ Ʒ
   ־

  ______________________________________________________________________
  <?php
  include ("debug2.inc");
  debug2_(__FILE__, __LINE__, "f_somevariable", $f_somevariable);

  function aa()
  {
          $aa = 8;
          debug2_(__FILE__, __LINE__, "aa", $aa);
  }
  ?>
  ______________________________________________________________________

  PHP α׷ ϰ Ǹ,  debug.out ̶ ȭϿ ̸,
  ιȣ,    Ÿ.

  Ϲ debug2_() ϶. α׷ debug2_() ȣ
   ڵ忡  ⵵  ࿡ ƹ 
  ʴ´. ֳϸ Ʒ Ѱ  ͸ Ǳ ̴.
  debug2_() Ÿϴ ð ̱  (copy)
  ٿֱ(paste) Ҽ ִ.  Vi  'yank to buffer'
   ̿ؼ ϶.

   ϷǸ ׽Ʈϰ  ø غ  ҽڵ忡
  debug2_ ȣ ͸ ϶. н Ʈ -

  ______________________________________________________________________
  bash$ mkdir production
  bash$ grep -v debug2_  filea.php3 > production/filea.php3
  ______________________________________________________________________

   ȭ  -

  ______________________________________________________________________
  bash$ mkdir production
  bash$ ls *.php3 | while read ans
  do
          grep -v  debug2_ $ans > production/$ans
  done
  ______________________________________________________________________

  ׸  production  ϴ°() ϶.

  7.  PHP 

    Ѱ  ֵ PHP ܰ ƴϴ.  Ʒ ִ°
  PHP (Ѱ)̴.(׷ Ѵ !!)

  1. PHP 100%  ü ũƮ  ƴϴ.  PHP ڵ
     ũⰡ 300,000    .  300,000  Ѵ
     PHPڵ带 ϱ  ̴.

  2. PHP "C" "C++"    Ѵ. ֳϸ PHP
     ũƮ ̰   ̱  ȭ
     "C++" ټ .  ְ  Ѵٸ "C++" Ŀؼ
     Ǯ(connection pooling) Ÿ̽/   CGI 
     ϰ C++ Ϸ Ƽ "-03" ɼ ϶.  PHP 4
     ִƼ PHP   ų̴.

  δ PHP       Ҽ ִ -

  1. PHP ũƮ  ϰ ũ Ǳ  ſ 
     ø̼ Ҽִ.

  2. PHP ø̼ ſ ̰ ڹٽũƮ 
     ΰͰ ٸ    ʴ.  PHP 
      ÷   ؾϴ Ϳ   ְ
      HTML  PHP ´ٴ  𸥴!

  3. PHP  SQL ͺ̽  Ἲ پ.

  4. PHP κ ü Ư  ִ.

  5. PHP "C++", Perl, Javascript    ҽڵ带
     ŽҼ ִ α׷  'ptags/ctags'  ִ.

  6. PHP ӵ ų ִ Ƽ  ִ.

  7. PHP  н, ,  95/NT/200  Ǹ ASP,
     JSP ٸͺ  .

  8. PHP     ִ.

  :   100%  ü ũƮ  Ѵٸ "ݵ"
  Python ض. 'Python' ó ü ũƮ̴.
  <http://www.python.org> ִ.

  8.  ִ  URL

  C, C++ ִ  Ҹ 湮϶ -

  o  C++, C  ÷ Vim ؽƮ 
     <http://metalab.unc.edu/LDP/HOWTO/Vim-HOWTO.html>

  o  PHP PostgreSQL  SQL database server
     <http://metalab.unc.edu/LDP/HOWTO/PostgreSQL-HOWTO.html>

  o  C++ α׷  Source code control system CVS HOWTO
     <http://metalab.unc.edu/LDP/HOWTO/CVS-HOWTO.html>

  o  Linux goodies main site  <http://www.aldev.8m.com>

  o  Linux goodies mirror site  <http://aldev.webjump.com>

  9.  ̹ ٸ 

  ̹ DVI, Postscript, Latex, Adobe Acrobat PDF, LyX, GNU-info,
  HTML, RTF(Rich Text Format), Plain-text, Unix man pages  SGML
  11 ٸ  ִ.

  o   HOWTO  HTML, DVI, Postscritp Ǵ SGML   tar
     ball  <ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO/other-
     formats/>  Ҽ ִ.

  o  ܼ ؽƮ 
     <ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO>

  o  Ҿ, , ݾƾ, ߱, Ϻ  
     <ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO>  Ҽ ִ.
     ٸ  Ͻ   ȯѴ.

     ̹  <http://www.sgmltools.org> Ҽ ִ "SGML-Tools"
      ؼ ۼǾ.      ؼ ҽ
      Ҽ ִ.

  o  sgml2html CVS-HOWTO.sgml     (html ȭ  )

  o  sgml2rtf  CVS-HOWTO.sgml     (RTF ȭ  )

  o  sgml2latex CVS-HOWTO.sgml    (latex ȭ  )

  LaTex  sgml2latex ( dvips) ׸ ũιƮ(Acrobat) distill
  ( <http://www.adobe.com>)   ƮũƮ  ó
  PDFȭϷ  ٲܼ ִ.   ɵ̴:

  ______________________________________________________________________
  bash$ man sgml2latex
  bash$ sgml2latex filename.sgml
  bash$ man dvips
  bash$ dvips -o filename.ps filename.dvi
  bash$ distill filename.ps
  bash$ man ghostscript
  bash$ man ps2pdf
  bash$ ps2pdf input.ps output.pdf
  bash$ acroread output.pdf &
  ______________________________________________________________________

  Ǵ Ʈũ(Ghostscript)  ps2pdf Ҽ ִ.  ps2pdf
  Adobe's Acrobat Distiller product    ɰ ϰ
  Ѵ. ƮũƮ ȭ PDF(Portable Document Format)
  ٲپش.  ps2pdf  ũƮ(command script/ġ)
  Ghostscript ҷ , pdfwrite Ҹ Ư  ̽
  Ͽ ȴ. ps2pdf ϱ  Ghostscript  Ҷ
  pdfwrite ġ makefile ԵǾѴ; ڼ  Ghostscript
  ġ  ƶ.

  ̹  ã ִ -

  o  <http://sunsite.unc.edu/LDP/HOWTO/CVS-HOWTO.html>

    ̷ Ʈ ̹ ã ִ -

  o  <http://www.caldera.com/LDP/HOWTO/CVS-HOWTO.html>

  o  <http://www.WGS.com/LDP/HOWTO/CVS-HOWTO.html>

  o  <http://www.cc.gatech.edu/linux/LDP/HOWTO/CVS-HOWTO.html>

  o  <http://www.redhat.com/linux-info/ldp/HOWTO/CVS-HOWTO.html>

  o  ٸ Ű  ̷Ʈ(network-address-wise)
     <http://sunsite.unc.edu/LDP/hmirrors.html> ã ִ.
     Ʈ ϰ /LDP/HOWTO/CVS-HOWTO.html 丮 .

   dvi  Ǿִ   ؼ xdvi α׷
  ϶.  xdvi α׷   tetex-xdvi*.rpm Ű
  ְ ޴ư ControlPanel | Applications | Publishing | TeX  ִ.
  dvi  б    ϶ -

               xdvi -geometry 80x90 howto.dvi
               man xdvi

  ׸ 콺 Ͽ  ũ⸦ ϶.  ȭǥŰ, Page Up,
  Page Down keys  , Ʒ, ߰, ,    ŽҼ
  ִ.    'x' .

  ȭ  ִ.    ghostscript  ghostscript*.rpm
  Ű gv gv*.rpm Ű ִ. ׸ ControlPanel |
  Applications | Graphics ޴ ư ġѴ. gv  ghostscript 
  ģ α׷̴.  ׸ ghostscript gv OS/2, Windows 95  NT
  뵵 Ѵ. ׸  ü    ִ.

  o  Get ghostscript for Windows 95, OS/2, and for all OSes from
     <http://www.cs.wisc.edu/~ghost>

  ƮũƮ  б   Է϶ -

                       gv howto.ps
                       ghostscript howto.ps

  ׽ ׺, ũμƮ ͳ ͽη,  ٷ
   Ǵ 10 ̻ ζ HTML ˹ 
  ִ.

  LyX  X-Windows α׷ latex   ִ.

  10.  ۱

  ۱å LDP(  Ʈ) GNU/GPL .  LDP
  GNU/GPL Ʈ̴.  ߰ 䱸 -  ̸, ̸ּҿ 
  ۱ǻ ϶.    ̹  ̳ ÷
  Ұ ̹ ڿ ˷־.

  11.  η A Database Wrapper 

   : Barton Greg greg@createtech.com ȭ 
   'ٸ̸ '  pgsql.lib  ԷϽÿ.

  ______________________________________________________________________
  ̰ PostgresSQL  ͺ̽  ٸ 
  ͺ̽  ݸ ġ Ҽ ִ.

  <?php

  if ($dbObjDefined  !=  1)
  {
          $dbObjDefined  =  1;

          // Wrapper  class  for  database  calls
          class  dbObj
          {
                  // Connection  handle  to  database
                  var  $conn;

                  // Default  connection  parameters
                  var  $host  =  "YourSite.com";
                  var  $user  =  "johndoe";
                  var  $password  =  "pwd";
                  var  $port  =  "5432";
                  var  $dbname  =  "MyDB";

                  // Open  initial  connection.  $params  is
                  // an  associative  array  holding
                  // parameters  to  the  pg_Connect  function.
                  function  init($params)
                  {
                          if(isset($parame[host]))
                                  $host  =  $parame[host];
                          else
                                  $host  =  $this->host;

                          if(isset($parame[user]))
                                  $user  =  $parame[user];
                          else
                                  $user  =  $this->user;

                          if(isset($parame[password]))
                                  $password  =  $parame[password];
                          else
                                  $password  =  $this->password;

                          if(isset($parame[port]))
                                  $port  =  $parame[port];
                          else
                                  $port  =  $this->port;

                          if(isset($parame[dbname]))
                                  $dbname  =  $parame[dbname];
                          else
                                  $dbname  =  $this->dbname;

                          $this->conn  =  pg_Connect ( "  host=$host  user=$user  password=$password  port=$port  dbname=$dbname ");
                  }

                  // Send  SQL  to  database  connection.
                  // Return  recordset  object  on  success.
                  // Return  0  on  failure.
                  function  exec($SQL)
                  {
                          $this->resultset  =  pg_Exec($this->conn,  $SQL);

                          if  ($this->resultset)
                          {
                                  $recset  =  new  recordset;
                                  $recset->init($this->resultset);
                                  return  $recset;
                          }
                          else
                          {
                                  return  0;
                          }
                  }

                  function valid()
                  {
                          return $this->resultset;
                  }

                  // Close  connection  to  database
                  function  free()
                  {
                          pg_close($this->conn);
                  }
          };

          /*
          ** This  is  a  simple  recordset  class  which  can  be
          ** traversed  using  next(),  prev(),  and  current()  methods.
          ** It  is  initialized  from  a  resultset  returned  from  the
          ** function  "pg_Exec"  or  can  be  generated  by  a  call  to  the
          ** exec  method  from  the  dbObj class given above.
          ** Below "Tuples" means rows.
          */
          class  recordset
          {
                  var  $resultset;
                  var  $index;
                  var  $numFields;
                  var  $numTuples;

                  function  init($newResultset)
                  {
                          $this->resultset  =  $newResultset;
                          $this->index  =  0;
                          $this->numFields  =  pg_NumFields($this->resultset);
                          $this->numTuples  =  pg_NumRows($this->resultset);
                  }

                  // Used in display() below
                  function valid()
                  {
                          return $this->resultset;
                  }

                  // Get  a  value  by  row  number  and  either
                  // column  name  or  column  number
                  function  getVal($row,  $col)
                  {
                          return  pg_Result($this->resultset,  $row,  $col);
                  }

                  // Return  an  array  of  field  names
                  function  getFields()
                  {
                          for ($i=0;  $i < $this->numFields;  $i++)
                                  $retArray[] = pg_FieldName($this->resultset,  $i);
                          return  $retArray;
                  }

                  // Get  number  of  columns  in  resultset
                  function  getNumFields()
                  {
                          return  $this->numFields;
                  }

                  // Get  a  tuple  (associative  array  of
                  // column  values)  by  row  number
                  function  getTupleDirect($row)
                  {
                          for ($i=0;  $i < $this->numFields;  $i++)
                          {
                                  $retArray[pg_FieldName($this->resultset,  $i)]  =
                                          pg_Result($this->resultset,  $row,  $i);
                          }
                          return  $retArray;
                  }

                  // Get  an  array  filled  with  all  values  in  a  column
                  // (using  either  column  name  or  column  number)
                  function  getColumn($col)
                  {
                          for ($i=0; $i < $this->numTuples; $i++)
                                  $retArray[]  =  pg_Result($this->resultset,  $i,  $col);
                          return  $retArray;
                  }

                  // Return  the  number  of  records  in  the  recordset
                  function  getNumTuples()
                  {
                          return  $this->numTuples;
                  }

                  // Get  tuple  pointed  to  by  the  current  index
                  function  getTuple()
                  {
                          if ($this->index >= 0  &&  $this->index  <  $this->numTuples)
                                  return  $this->getTupleDirect($this->index);
                          else
                                  return  0;
                  }

                  function valueof($col)
                  {
                          if ($col < $this->numFields)
                          {
                                  return pg_Result($this->resultset,  $this->index,  $col);
                          }
                          else
                          {
                                  return "";
                          }
                  }

                  // Reached last row - end of rows ? Used in display() below
                  function eof()
                  {
                          return $this->index == $this->numTuples;
                  }

                  // Return  1  if  index  is  within  bounds  of  the  recordset
                  function  current()
                  {
                          if ($this->index >= 0  &&  $this->index  <  $this->numTuples)
                                  return  1;
                          else
                                  return  0;
                  }

                  // Increment  index. Used in display() below
                  function  next()
                  {
                          if ($this->index < $this->numTuples)
                          {
                                  $this->index++;
                                  return  1;
                          }
                          else
                          {
                                  return  0;
                          }
                  }

                  // Decrement  index
                  function  prev()
                  {
                          if ($this->index  >=  0)
                          {
                                  $this->index--;
                                  return  1;
                          }
                          else
                          {
                                  return  0;
                          }
                  }

                  // Reset  index  to  0 - See also first()
                  function  reset()
                  {
                          $this->index  =  0;
                  }

                  // See also reset(). Used in display() below
                  function  first()
                  {
                          $this->index  =  0;
                  }

                  function last()
                  {
                          $this->index = $this->numTuples -1 ;
                  }

                  // Used in display() below
                  function showheader($col, $fmt = "")
                  {
                          printf("\t< th %s>%s< /th >\n", $fmt,
                          is_string($col) ? $col : pg_fieldname($this->resultset, $col));
                  }

                  // Used in display() below
                  function showvalue($col, $fmt =  "", $def =  " ")
                  {
                          $v = $this->valueof($col);
                          printf( "\t< td %s>%s< /td>\n", $fmt, $v ==  "" ? $def : $v);
                  }

                  function showurl($col, $fmt =  "")
                  {
                          $v = $this->valueof($col);
                          if ( $v !=  "" )
                          {
                                  printf("\t< td %s> < /td>\n", $fmt);
                          }
                          else
                          {
                                  printf( "\t< td %s>< a href=%s>%s< /a>< /td>\n", $fmt, $v, $v);
                          }
                  }

                  function display()
                  {
                          if (!$this->valid() )
                          {
                                  return;
                          }

                          printf( "<table cellspacing=1 cellpadding=1 border=1>\n");

                          printf( "<tr>\n");
                          for ($c = 0; $c < $this->cols; $c++ )
                          {
                                  $this->showheader($c);
                          }
                          printf( "< /tr>\n");

                          $this->first();
                          while (!$this->eof())
                          {
                                  printf( "<tr>\n");

                                  for ($c = 0; $c < $this->cols; $c++)
                                  {
                                          $this->showvalue($c);
                                  }

                                  printf( "< /tr>\n");
                                  $this->next();
                          }
                          printf("< /table\n");
                  }

                  // Free  memory  allocated  to  recordset.
                  function  free()
                  {
                          pg_Freeresult($this->resultset);
                  }
          };
  }

  ?>
  ______________________________________________________________________

  12.  η B SQL abstraction Example

   : Gianugo Rabellino nemorino@opera.it ȭ 
   'ٸ̸ '  sqlabst.lib 
  ԷϽÿ.

  ______________________________________________________________________

  PX: PHP Code Exchange
  <?php

  /*
  *    SAL - SQL Abstraction Library
  *           version 0.01
  */

  /*
  ** Set the variable $dbtype to any of the following
  ** values: MySQL, mSQL, Postgres, ODBC before including this library
  */
  // $dbtype = "MySQL";
  // $dbtype = "mSQL";
  // $dbtype = "PostgreSQL";
  // $dbtype = "ODBC";

  // SQL_connect($host, $user, $password, $db)
  // returns the connection ID

  function SQL_connect($host, $user, $password, $db)
  {
          global $dbtype;

          switch ($dbtype)
          {
                  case  "MySQL":
                          $conn=mysql_pconnect($host, $user, $password);
                          mysql_select_db($db);
                          return $conn;
                          break;;

                  case  "mSQL":
                          $conn=msql_pconnect($host);
                          msql_select_db($db);
                          return $conn;
                          break;;

                  case  "PostgreSQL":
                          $conn=pg_pconnect($host, "5432", "",$db);
                          return $conn;
                          break;;

                  case  "ODBC":
                          $conn=odbc_pconnect($db,$user,$password);
                          return $conn;
                          break;;

                  default:
                          $conn=mysql_pconnect($host, $user, $password);
                          mysql_select_db($db);
                          return $conn;
                          break;;
          }
  }

  // SQL_query($host, $user, $password, $db)
  // executes an SQL statement, returns a result identifier
  function SQL_query($query, $id)
  {
          global $dbtype;
          switch ($dbtype)
          {
                  case  "MySQL":
                          $res=mysql_query($query, $id);
                          return $res;
                          break;;

                  case  "mSQL":
                          $res=msql_query($query, $id);
                          return $res;
                          break;;

                  case  "PostgreSQL":
                          $res=pg_exec($id,$query);
                          return $res;
                          break;;

                  case  "ODBC":
                          $rid=odbc_prepare($id,$query);
                          $res=odbc_execute($rid);
                          return $res;
                          break;;

                  default:
                          $res=mysql_query($query, $id);
                          return $res;
                          break;;
          }
  }

  // SQL_num_rows($host, $user, $password, $db)
  // given a result identifier, returns the number of affected rows
  function SQL_num_rows($res)
  {
          global $dbtype;

          switch ($dbtype)
          {
                  case  "MySQL":
                          $rows=mysql_num_rows($res);
                          return $rows;
                          break;;

                  case  "mSQL":
                          $rows=msql_num_rows($res);
                          return $rows;
                          break;;

                  case  "PostgreSQL":
                          $rows=pg_numrows($res);
                          return $rows;
                          break;;

                  case  "ODBC":
                          $rows=odbc_num_rows($res);
                          return $rows;
                          break;;

                  default:
                          $rows=mysql_num_rows($res);
                          return $rows;
                          break;;
          }
  }

  // SQL_fetchrow($res,$row)
  // given a result identifier, returns an array with the resulting row
  // Needs also a row number for compatibility with PostgreSQL
  function SQL_fetch_row($res, $nr)
  {
          global $dbtype;

          switch ($dbtype)
          {
                  case  "MySQL":
                          $row = array();
                          $row = mysql_fetch_row($res);
                          return $row;
                          break;;

                  case  "mSQL":
                          $row = array();
                          $row = msql_fetch_row($res);
                          return $row;
                          break;;

                  case  "PostgreSQL":
                          $row = array();
                          $row = pg_fetch_row($res,$nr);
                          return $row;
                          break;;

                  case  "ODBC":
                          $row = array();
                          $cols = odbc_fetch_into($res, $nr, &$row);
                          return $row;
                          break;;

                  default:
                          $row = array();
                          $row = mysql_fetch_row($res);
                          return $row;
                          break;;
          }
  }

  // SQL_fetch_array($res,$row)
  // given a result identifier, returns an associative array
  // with the resulting row using field names as keys.
  // Needs also a row number for compatibility with PostgreSQL.
  function SQL_fetch_array($res, $nr)
  {
          global $dbtype;

          switch ($dbtype)
          {
                  case  "MySQL":
                          $row = array();
                          $row = mysql_fetch_array($res);
                          return $row;
                          break;;

                  case  "mSQL":
                          $row = array();
                          $row = msql_fetch_array($res);
                          return $row;
                          break;;

                  case  "PostgreSQL":
                          $row = array();
                          $row = pg_fetch_array($res,$nr);
                          return $row;
                          break;;

                  /*
                  * ODBC doesn't have a native _fetch_array(), so we have to
                  * use a trick. Beware: this might cause HUGE loads!
                  */

                  case  "ODBC":
                          $row = array();
                          $result = array();
                          $result = odbc_fetch_row($res, $nr);
                          $nf = count($result)+2;  /* Field numbering starts at 1 */
                          for ($count=1; $count < $nf; $count++)
                          {
                                  $field_name = odbc_field_name($res, $count);
                                  $field_value = odbc_result($res, $field_name);
                                  $row[$field_name] = $field_value;
                          }
                          return $row;
                          break;;
          }
  }
  ______________________________________________________________________

  13.  η C PostgreSQL large object 

   : PHP code exchange px@sklar.com ȭ 
   'ٸ̸ '  pgsql_largeobj.lib 
  ԷϽÿ.

  ______________________________________________________________________

  PX: PHP Code Exchange - PostgreSQL large object access

  <?
          $database = pg_Connect ( "",  "",  "",  "",  "jacarta");
          pg_exec ($database,  "BEGIN");
          $oid = pg_locreate ($database);
          echo ( "$oid\n");
          $handle = pg_loopen ($database, $oid,  "w");
          echo ( "$handle\n");
          pg_lowrite ($handle,  "foo");
          pg_loclose ($handle);
          pg_exec ($database,  "COMMIT");
          pg_close ($database);
  ?>
  ______________________________________________________________________

  14.  η D   

  ȭ   'ٸ̸ ' 
  user_pw.lib  ԷϽÿ.

  PHP 3 ޴󿡼 : PHP ġ ϶ ۵Ѵ.  $PHP_AUTH_USER
   $PHP_AUTH_PW  ϴ , ̸ йȣ Ȯθ
  ϱ  𸥴. Ƹ ͺ̽  ų adm
  ȭϿ ãƺ ɰ̴.

  ______________________________________________________________________
  <?php
          if (!$PHP_AUTH_USER)
          {
                  Header("WWW-authenticate: basic realm=\"My Realm\"");
                  Header("HTTP/1.0 401 Unauthorized");
                  echo "Text to send if user hits Cancel button\n";
                  exit;
          }
          else
          {
                  echo "Hello $PHP_AUTH_USER.<P>";
                  echo "You entered $PHP_AUTH_PW as your password.<P>";
          }
  ?>
  ______________________________________________________________________

  15.  η E Ʈũ  

   ȭ   network.lib ̸ 'ؽƮ(Text)'
  · ϶.

  PHP: network adminstrator's best friend from
  <http://www.phpWizard.net>

  ڷμ Ƹ ping, whois, nslookup   
  Ұ̴. ׷  繫ǿ   ϳ ؾߵǴµ
  telnet Ҽ ٸ Ұΰ?  PHP Ŵ 'Ʈũ'
  function ãƺ  ̴.

   ۵ :

   ߿ Լ fsockopen()̴. Լ ϸ  
   Ʈε Ҽ ְ   Ҽ ִ. Լ 
    :

  ______________________________________________________________________
          int fsockopen(string hostname, int port, int [errno], string [errstr]);
  ______________________________________________________________________

   2   ˼ ְ,  2  ɼ̰, 
  óϱ  δ. "errno" "errstr"  ؼ ̷
  Ѵ.  "  ̷"  ǹ̴   Ѵٴ
  ̴.  , Լ Ǵ    ʴ´.

  ׷,  ϱ  Լ ϰ  Ʈ϶ :

  ______________________________________________________________________
  function get_headers($host, $path = "/")
  {
          $fp = fsockopen ("$host", 80, &$errnr, &$errstr) or die("$errno: $errstr");
          fputs($fp,"GET $path HTTP/1.0\n\n");
          while (!$end)
          {
                  $line = fgets($fp, 2048);
                  if (trim($line) == "")
                          $end = true;
                  else
                          echo $line;
          }
          fclose($fp);
  }
  ______________________________________________________________________

    fsockopen() ȣؼ  Ϳ ó
   ˾ƺ̴.(fred, fwrite ) HTTP/1.0 Ŭ̾Ʈ
  ȴٴ° ϶.  - name-based ȣƮ 
  ʴ´.

  :

  Ϲ ٸ Ʈ  Ҽ ִ.  PHP  ΰ Ŭ̾Ʈ
    Ҽ ִ.  ΰ  ()ϱ  Ʒ ִ
   ϶.

  ______________________________________________________________________
  function finger ($host, $user)
  {
          $fp = fsockopen($host, 79, &$errno, &$errstr) or die("$errno: $errstr");
          fputs($fp, "$user\n");
          while (!feof($fp))
                  echo fgets($fp, 128);
          fclose($fp);
  }
  ______________________________________________________________________

  Whois: ̽(whois)  ϴ°͵  ̴:

  ______________________________________________________________________
  // domain is like "phpwizard.net"
  function whois($domain, $server="whois.internic.net")
  {
          $fp = fsockopen ($server, 43, &$errnr, &$errstr) or die("$errno: $errstr");
          fputs($fp, "$domain\n");
          while (!feof($fp))
                  echo fgets($fp, 2048);
          fclose($fp);
  }
  ______________________________________________________________________

  ŷ, ͺŷ  : ׷ Լ ϴµ  ִ. 
   ۵Ѵ.

  1. ȣð  ϶

  2. ϰ ִ  ְ ۵Ҷ.  ׷ , 
     ũƮ ɶ ۵Ѵ.  ׷ Ǵ  Ͽ
     ŷǸ ᰡ ʱ ̴.  set_socket_blocking()̶
     Լ   Ѵ: Լ 絿 (ù°
     μ: ) ŷ(ι μ:true) (false)(°
     μ:false) Ѵ. ͺŷ ϸ, ΰ(finger)Լ
      ̴:(:  ̻ϳ׿)

  ______________________________________________________________________
          $fp = fsockopen($host, 79, &$errno, &$errstr) or die("$errno: [ ] $errstr");
          set_socket_blocking($fp, 0);
          fputs($fp, "$user\n");

          $stop = time() + $timeout;
          while (!feof($fp) && time() < $stop )
                  echo fgets($fp, 128);
          fclose($fp);
  ______________________________________________________________________

  ͺŷ (socket calls) ϱ  3 Լ 
     ܵд.

  16.  η F PostgreSQL Database Wrapper 

   : Joe Thong darkjoe@softhome.net Ʈ URL:
  <http://phpdb.linuxbox.com>

  :   ͺ̽      PHP
  Ÿ̽ .  ͺ̽  phpDB  ڵ 
  ȴ.

  ȭ   'ٸ̸ '  phpDB-
  postgresql.lib  ԷϽÿ.

  ______________________________________________________________________
  <?php
  /*
  Name: phpDB PostgreSQL module
  Version: 1.02bR6
  Description: A PHP database wrapper for various database
          servers with a powerful recordset for result data
          manipulation.  Database results are flushed
          automatically by phpDB.
  */

  /* define this module, to prevent double class declaration.     */
  if (!defined("_PHPDB_ABSTRACT_LAYER")) {
          define("_PHPDB_ABSTRACT_LAYER", 1 );
  }
  else
          return;

  //---------------------------------------
           Class Name: phpDB
  //---------------------------------------
  class phpDB
  {
          /*      public variables        */
          var $version = '1.02bR6'; // Version number of phpDB
          // This variable keeps what database type is going to
          // be used.  Current supported database server are
          // MySQL, MSQL, SQL Server, and Sybase
          var $databaseType = '';
          // Specifies which database is going to be used
          var $databaseName = '';
          // The hostname of the database server, port
          // number is optional.  e.g: "db.devNation.com"
          var $hostname = '';
          var $username = ''; // used to connect to the database server
          var $password = ''; // Password for the username

          // Private variables ------ starts with underscore
          // An array of executed querys. For results cleanup purposes.
          var $_queryIDList = array();
          // The returned link identifier whenever a
          // successful database connection is made
          var $_connectionID      = -1;
          // A variable which was used to keep the returned
          // last error message.  The value will then returned
          // by the errorMsg() function
          var $_errorMsg = '';

          // This variable keeps the last created result
          // link identifier
          var $_queryID = -1;
          // A boolean variable to state whether its a persistent
          // connection or normal connection
          var     $_isPersistentConnection = false;
          // Holds the newly created result object,
          // returned via the execute() method
          var $_tempResultObj = '';

          // A constructor function for the phpDB object.
          // When initializing, specify the dbType i.e: "mysql",
          // "msql", "postgresql", "mssql", and "sybase"
          function phpDB($dbType = "postgresql")
          {
                  switch ($dbType) {
                          case "mysql":
                          case "msql":
                          case "postgresql":
                          case "mssql":
                          case "sybase":
                          case "informix":
                                  $this->databaseType = $dbType;
                                  break;
                          default:
                                  return false;
                  }
          }

          // Returns: A positive link identifier on success, or
          // false on error.      Connect to the server with the provided
          // arguments. The connection to the server will be closed
          // when the script terminates, unless close() function is
          // called beforehand
          function connect($argHostname = "", $argUsername = "",
                  $argPassword = "", $argDatabaseName = "")
          {
                  $connString = "";
                  $hostPieces = array();
                  /*      Must specify the database argument      */
                  if (!$argDatabaseName) {
                          return false;
                  }
                  if ($argHostname != "") {
                          $this->hostname = $argHostname;
                  }
                  if ($argUsername != "") {
                          $this->username = $argUsername;
                  }
                  if ($argPassword != "") {
                          $this->password = $argPassword;
                  }
                  if ($argDatabaseName != "") {
                          $this->databaseName = $argDatabaseName;
                  }
                  $hostPieces = split(":", $this->hostname);
                  if ($hostPieces[0]) {
                          $connString .= "host=$hostPieces[0]";
                          if (isset($hostPieces[1])) {
                                  $connString .= " port=$hostPieces[1]";
                          }
                  }
              if ($this->username) {
                          $connString .= " user=$this->username";
                  }
              if ($this->password) {
                          $connString .= " password=$this->password";
                  }
                  $connString .= " dbname=$this->databaseName";

                  $this->_connectionID = @pg_Connect($connString);
                  return $this->_connectionID;
          }

          // Returns: A positive link identifier on success, or
          // false on error.  Connect to the server with the
          // provided arguments. The connection to the server will
          // not be closed when the script terminates. Instead it
          // will be kept for later future use
          function pconnect($argHostname = "", $argUsername = "",
                  $argPassword = "", $argDatabaseName = "")
          {
                  $connString = "";
                  $hostPieces = array();
                  /*      Must specify the database argument      */
                  if (!$argDatabaseName) {
                          return false;
                  }
                  if ($argHostname != "") {
                          $this->hostname = $argHostname;
                  }
                  if ($argUsername != "") {
                          $this->username = $argUsername;
                  }
                  if ($argPassword != "") {
                          $this->password = $argPassword;
                  }
                  if ($argDatabaseName != "") {
                          $this->databaseName = $argDatabaseName;
                  }
                  $hostPieces = split(":", $this->hostname);
                  if ($hostPieces[0]) {
                          $connString .= "host=$hostPieces[0]";
                          if (isset($hostPieces[1])) {
                                  $connString .= " port=$hostPieces[1]";
                          }
                  }
              if ($this->username) {
                          $connString .= " user=$this->username";
                  }
              if ($this->password) {
                          $connString .= " password=$this->password";
                  }
                  $connString .= " dbname=$this->databaseName";

                  $this->_connectionID = @pg_pConnect($connString);
                  if ($this->_connectionID) {
                          $this->_isPersistentConnection = true;
                  }
                  return $this->_connectionID;
          }

          // Returns: true on success, false on error Select
          // the database name to be used PostgreSQL
          // Note:        function Not available
          function selectDB($dbName) {
                          return false;
          }

          // Returns: the Recordset object disregard success
          // or failure Send the sql statement to the database server
          function execute($sql = "") {
                  // Instantiate an object without considering whether
                  // the query return any results or not
                  $this->_queryID = @pg_Exec($this->_connectionID, $sql);
                  $this->_tempResultObj = new Recordset($this->_queryID);
                  $this->_insertQuery($this->_queryID);
                  return $this->_tempResultObj;
          }

          // Returns: the last error message from previous
          // database operation
          function errorMsg() {
                  $this->_errorMsg = @pg_errormessage($this->_connectionID);
              return $this->_errorMsg;
          }

          // Returns: true on success, false on failure
          // Close the database connection
          function close() {
                  if ($this->_queryIDList && sizeof($this->_queryIDList > 0)) {
                          while(list($_key, $_resultID) = each($this->_queryIDList)) {
                                  @pg_freeresult($_resultID);
                          }
                  }
                  // If its not a persistent connection, then
                  // only the connection needs to be closed
                  if ($this->_isPersistentConnection != true) {
                          return @pg_close($this->_connectionID);
                  }
                  else {
                          return true;
                  }
          }

          // A PRIVATE function used by the constructor function
          // of the query object.  insert the successful returned
          // query id to the query id list.  Used for later results
          // cleanup.  A private function that's never meant to
          // be used directly
          function _insertQuery($query_id) {
                  $this->_queryIDList[] = $query_id;
          }
  }

  //------------------------------
           Class Name: Recordset
  //------------------------------
  class Recordset
  {
          /*      public variables        */
          var $fields;
          // indicates that the current record position is before
          // the first record in a Recordset object
          var $BOF = null;

          // indicates that the current record position is after
          // the last record in a Recordset object
          var $EOF = null;

          /*      private variables       */
          var $_numOfRows = -1; // NEVER change the value! READ-ONLY!
          var $_numOfFields = -1; // NEVER change the value! READ-ONLY!
          // Holds anything that was returned from the database specific functions
          var $_tempResult = '';
          // This variable keeps the result link identifier
          var $_queryID = -1;
          // This variable keeps the current row in the Recordset
          var $_currentRow = -1;

          // Returns: query id on success and false if
          // failed Constructor function
          function Recordset($queryID)
          {
                  $this->_queryID = $queryID;
                  if ($queryID) {
                          $this->_numOfRows = @pg_numrows($this->_queryID);
                          /*      pg_numrows() returns -1 on error        */
                          if ($this->_numOfRows == -1) {
                                  $this->_numOfRows = 0;
                          }
                          $this->_numOfFields = @pg_numfields($this->_queryID);
                          /*      pg_numfields() returns -1 on error      */
                          if ($this->_numOfFields == -1) {
                                  $this->_numOfFields = 0;
                          }
                  }
                  else {
                          $this->_numOfRows = 0;
                          $this->_numOfFields = 0;
                  }
                  /*      If result set contains rows     */
                  if ($this->_numOfRows > 0 && $this->_currentRow == -1) {
                          $this->_currentRow = 0;
                          $this->fields = @pg_fetch_array($this->_queryID, $this->_currentRow);
                          $this->EOF = false;
                          $this->BOF = false;
                  }
                  return $this->_queryID;
          }

          // Returns: true if successful, false if fail Set the Recordset
          // pointer to a specified field offset. If the next call to
          // fetchField() won't include a field offset, this field would
          // be returned.  PostgreSQL Note:       function Not available
          function fieldSeek($fieldOffset = -1) {
                  $this->_tempResult = false;
                  return $this->_tempResult;
          }

          // Returns: an object containing field information.  Get column
          // information in the Recordset object. fetchField() can be used
          // in order to obtain information about fields in a certain query
          // result. If the field offset isn't specified, the next field
          // that wasn't yet retrieved by fetchField() is retrieved.
          // PostgreSQL Note:     function Not available
          function fetchField($fieldOffset = -1) {
                  $this->_tempResult = false;
                  return $this->_tempResult;
          }

          // Returns: true if there still rows available, or false if there
          // are no more rows.  Moves to the next row in a specified Recordset
          // object and makes that record the current row and the data
          // corresponding to the row will be retrieved into the fields
          // collection.  Note: Unlike the moveRow() method, when _currentRow
          // is getNumOfRows() - 1, EOF will immediately be true.  If row number
          // is not provided, the function will point to the
          // first row automatically
          function nextRow() {
                  if ($this->getNumOfRows() > 0) {
                          $this->fields = array();
                          $this->_currentRow++;
                          $this->fields = @pg_fetch_array($this->_queryID, $this->_currentRow);
                          /*      This is not working.  True all the time */
                          if ($this->fields) {
                                  $this->_checkAndChangeEOF($this->_currentRow - 1);
                                  return true;
                          }
                  }
                  $this->EOF = true;
                  return false;
          }

          // Returns: true on success, false on failure moveRow() moves
          // the internal row pointer of the Recordset object to point
          // to the specified row number and the data corresponding to
          // the row will be retrieved into the fields collection.  If
          // row number is not provided, the function will point to
          // the first row automatically
          function moveRow($rowNumber = 0) {
                  if ($rowNumber == 0) {
                          return $this->firstRow();
                  }
                  else if ($rowNumber == ($this->getNumOfRows() - 1)) {
                          return $this->lastRow();
                  }
                  if ($this->getNumOfRows() > 0 && $rowNumber < $this->getNumOfRows()) {
                          $this->fields = null;
                          $this->_currentRow = $rowNumber;
                          $this->fields = @pg_fetch_array($this->_queryID, $this->_currentRow);
                          /*      This is not working.  True all the time */
                          if ($this->fields) {
                                  // No need to call _checkAndChangeEOF() because
                                  // the possibility of moving to the last row
                                  // has been handled by the above code
                                  $this->EOF = false;
                                  return true;
                          }
                  }
                  $this->EOF = true;
                  return false;
          }

          // Returns: true on success, false on failure firstRow()
          // moves the internal row pointer of the Recordset object
          // to the first row and the data corresponding to the row
          // will be retrieved into the fields collection
          function firstRow() {
                  if ($this->getNumOfRows() > 0) {
                          $this->fields = array();
                          $this->_currentRow = 0;
                          $this->fields = @pg_fetch_array($this->_queryID, $this->_currentRow);
                          $this->EOF = true;
                          /*      This is not working.  True all the time */
                          if ($this->fields) {
                                  return true;
                          }
                  }
                  $this->EOF = true;
                  return false;
          }

          // Returns: true on success, false on failure lastRow()
          // moves the internal row pointer of the Recordset object
          // to the last row and the data corresponding to the row
          // will be retrieved into the fields collection
          function lastRow() {
                  if ($this->getNumOfRows() > 0) {
                          $this->fields = array();
                          $num_of_rows = $this->getNumOfRows();
                          /*      $num_of_rows decemented at above        */
                          $this->_currentRow = --$num_of_rows;
                          $this->fields = @pg_fetch_array($this->_queryID, $this->_currentRow);
                          /*      This is not working.  True all the time */
                          if ($this->fields) {
                                  /*      Special case for making EOF false.      */
                                  $this->EOF = false;
                                  return true;
                          }
                  }
                  $this->EOF = true;
                  return false;
          }

          // close() only needs to be called if you are worried about
          // using too much memory while your script is running. All
          // associated result memory for the specified result identifier
          // will automatically be freed
          function close() {
                  $this->_tempResult = @pg_freeresult($this->_queryID);
                  return $this->_tempResult;
          }

          // Returns: the number of rows in a result set.
          // Get number of rows in result
          function getNumOfRows() {
                  return $this->_numOfRows;
          }

          // Returns: the number of fields in a result set.
          // Get number of fields in result
          function getNumOfFields() {
                  return $this->_numOfFields;
          }

          /*      Check and change the status of EOF.     */
          function _checkAndChangeEOF($currentRow) {
                  if ($currentRow >= ($this->_numOfRows - 1)) {
                          $this->EOF = true;
                  }
                  else {
                          $this->EOF = false;
                  }
          }
  }
  ?>
  ______________________________________________________________________

  17.  η G Microsoft SQL Server DB Wrapper 

   : Joe Thong darkjoe@softhome.net Site URL:
  <http://phpdb.linuxbox.com>

  :   ͺ̽      PHP
  Ÿ̽ .  ͺ̽  phpDB  ڵ 
  ȴ.

  ȭ   'ٸ̸ '  phpDB-
  msql.lib  ԷϽÿ.

  ______________________________________________________________________
  <?php
  /*
  Name: phpDB Microsoft SQL Server module
  Version: 1.02bR6
  Description: A PHP database wrapper for various
          database servers with a powerful
          Recordset for result data manipulation.  Database
          results are flushed automatically by phpDB.
  */
  // Define this module, to prevent double class declaration
  if (!defined("_PHPDB_ABSTRACT_LAYER"))
  {
          define("_PHPDB_ABSTRACT_LAYER", 1 );
  }
  else
          return;

  //------------------------------
           Class Name: phpDB
  //------------------------------
  class phpDB
  {
          // public variables
          var $version = '1.02bR6'; // Version number of phpDB

          // This variable keeps what database type is going
          // to be used.  Current supported database server
          // are MySQL, MSQL, SQL Server, PostgreSQL and Sybase
          var $databaseType = '';
          var $databaseName = ''; // Specifies which database is going to be used

          // The hostname of the database server, port
          // number is optional.  e.g: "db.devNation.com"
          var $hostname = '';

          var $username = ''; // to connect to the database server
          var $password = '';     // Password for the username

          // Private variables ----- starts with underscore

          // An array of executed querys. For results cleanup purposes
          var $_queryIDList = array();

          // The returned link identifier whenever a
          // successful database connection is made
          var $_connectionID      = -1;

          // A variable which was used to keep the returned last
          // error message.  The value will then returned
          // by the errorMsg() function
          var $_errorMsg = '';
          // This variable keeps the last created result link identifier
          var $_queryID = -1;

          // A boolean variable to state whether its a
          // persistent connection or normal connection
          var     $_isPersistentConnection = false;

          // Holds the newly created result object, returned
          // via the execute() method
          var $_tempResultObj = '';

          //      A constructor function for the phpDB object.
          // When initializing, specify the dbType i.e: "mysql",
          // "msql", "postgresql", "mssql", and "sybase"
          function phpDB($dbType = "mssql")
          {
                  switch ($dbType)
                  {
                          case "mysql":
                          case "msql":
                          case "postgresql":
                          case "mssql":
                          case "sybase":
                          case "informix":
                                  $this->databaseType = $dbType;
                                  break;
                          default:
                                  return false;
                  }
          }

          // Returns: A positive link identifier on success,
          // or false on error.   Connect to the server with
          // the provided arguments. The connection to the server
          // will be closed when the script terminates, unless
          // close() function is called beforehand.
          function connect($argHostname = "", $argUsername = "",
                  $argPassword = "", $argDatabaseName = "")
          {
                  $boolDBSelected;
                  if ($argHostname != "") {
                          $this->hostname = $argHostname;
                  }
                  if ($argUsername != "") {
                          $this->username = $argUsername;
                  }
                  if ($argPassword != "") {
                          $this->password = $argPassword;
                  }
                  if ($argDatabaseName != "") {
                          $this->databaseName = $argDatabaseName;
                  }

                  $this->_connectionID = @mssql_connect($this->hostname, $this->username, $this->password);

                  if ($this->databaseName && $this->_connectionID) {
                          $boolDBSelected = @mssql_select_db($this->databaseName);
                          if(!$boolDBSelected) {  /*      If DB selection fails   */
                                  @mssql_close($this->_connectionID);     /*      Close the current connection    */
                                  return false;
                          }
                  }
                  return $this->_connectionID;
          }

          // Returns: A positive link identifier on success, or
          // false on error Connect to the server with the provided
          // arguments. The connection to the server will not be closed
          // when the script terminates. Instead it will be kept for
          // later future use
          function pconnect($argHostname = "", $argUsername = "",
                  $argPassword = "", $argDatabaseName = "")
          {
                  $boolDBSelected;
                  if ($argHostname != "") {
                          $this->hostname = $argHostname;
                  }
                  if ($argUsername != "") {
                          $this->username = $argUsername;
                  }
                  if ($argPassword != "") {
                          $this->password = $argPassword;
                  }
                  if ($argDatabaseName != "") {
                          $this->databaseName = $argDatabaseName;
                  }

                  $this->_connectionID = @mssql_pconnect($this->hostname, $this->username, $this->password);
                  if ($this->_connectionID) {
                          $this->_isPersistentConnection = true;
                  }

                  if ($this->databaseName && $this->_connectionID) {
                          $boolDBSelected = @mssql_select_db($this->databaseName);
                          if(!$boolDBSelected) {  /*      if DB selection fails   */
                                  return false;   /*      Persistent connection can't be closed   */
                          }
                  }
                  return $this->_connectionID;
          }

          //      Returns: true on success, false on error Select the
          // database name to be used
          function selectDB($dbName)
          {
                  $this->databaseName = $dbName;
                  if ($this->_connectionID) {
                          return @mssql_select_db($dbName);
                  }
                  else {
                          /*      No database selected    */
                          return false;
                  }
          }

          // Returns: the Recordset object disregard success or
          // failure Send the sql statement to the database server
          function execute($sql = "")
          {
                  $this->_queryID = @mssql_query($sql, $this->_connectionID);
                  // Instantiate an object without considering whether
                  // the query return any results or not
                  $this->_tempResultObj = new Recordset($this->_queryID);
                  $this->_insertQuery($this->_queryID);
                  return $this->_tempResultObj;
          }

          // Returns: the last error message from previous database
          // operation Note: This function is NOT available for
          // Microsoft SQL Server
          function errorMsg()
          {
                  $this->_errorMsg = "errorMsg() is not available for Microsoft SQL Server";
              return $this->_errorMsg;
          }

          /*      Returns: true on success, false on failure
                  Close the database connection.  */
          function close() {
                  if ($this->_queryIDList && sizeof($this->_queryIDList > 0)) {
                          while(list($_key, $_resultID) = each($this->_queryIDList)) {
                                  @mssql_free_result($_resultID);
                          }
                  }
                  // If its not a persistent connection, then
                  // only the connection needs to be closed
                  if ($this->_isPersistentConnection != true) {
                          return @mssql_close($this->_connectionID);
                  }
                  else {
                          return true;
                  }
          }

          // A PRIVATE function used by the constructor function of
          // the query object.  insert the successful returned
          // query id to the query id list.  Used for later results
          // cleanup.  A private function that's never meant to be
          // used directly
          function _insertQuery($query_id) {
                  $this->_queryIDList[] = $query_id;
          }
  }

  //---------------------------------------
           Class Name: Recordset
  //---------------------------------------
  class Recordset
  {
          /*      public variables        */
          var $fields;
          // indicates that the current record position is
          // before the first record in a Recordset object
          var $BOF = null;
          // indicates that the current record position is
          // after the last record in a Recordset object
          var $EOF = null;

          // Private variables
          var $_numOfRows = -1; // NEVER change the value!  READ-ONLY!
          var $_numOfFields = -1; // NEVER change the value!  READ-ONLY!

          // Holds anything that was returned from the
          // database specific functions
          var $_tempResult = '';
          // This variable keeps the result link identifier
          var $_queryID = -1;
          // This variable keeps the current row in the Recordset
          var $_currentRow = -1;

          // Returns: query id on success and false if
          // failed Constructor function
          function Recordset($queryID)
          {
                  $this->_queryID = $queryID;
                  if ($queryID) {
                          $this->_numOfRows = @mssql_num_rows($this->_queryID);
                          $this->_numOfFields = @mssql_num_fields($this->_queryID);
                  }
                  else {
                          $this->_numOfRows = 0;
                          $this->_numOfFields = 0;
                  }
                  // If result set contains rows
                  if ($this->_numOfRows > 0 && $this->_currentRow == -1) {
                          $this->_currentRow = 0;
                          $this->fields = @mssql_fetch_array($this->_queryID);
                          $this->EOF = false;
                          $this->BOF = false;
                  }
                  return $this->_queryID;
          }
          // Returns: true if successful, false if fail Set
          // the Recordset pointer to a specified field offset.
          // If the next call to fetchField() won't include a
          // field offset, this field would be returned
          function fieldSeek($fieldOffset = -1) {
                  $this->_tempResult = @mssql_field_seek($this->_queryID, $fieldOffset);
                  return $this->_tempResult;
          }

          // Returns: an object containing field information.
          // Get column information in the Recordset object.
          // fetchField() can be used in order to obtain information
          // about fields in a certain query result. If the field
          // offset isn't specified, the next field that wasn't yet
          // retrieved by fetchField() is retrieved
          function fetchField($fieldOffset = -1) {
                  if ($fieldOffset != -1) {
                          $this->_tempResult = @mssql_fetch_field($this->_queryID, $fieldOffset);
                  }
                  // The $fieldOffset argument is not provided thus its -1
                  else if ($fieldOffset == -1) {
                          $this->_tempResult = @mssql_fetch_field($this->_queryID);
                  }
                  return $this->_tempResult;
          }

          // Returns: true if there still rows available, or false
          // if there are no more rows.  Moves to the next row in a
          // specified Recordset object and makes that record the current
          // row and the data corresponding to the row will be retrieved
          // into the fields collection.  Note: Unlike the moveRow() method,
          // when _currentRow is getNumOfRows() - 1, EOF will immediately be
          // true.  If row number is not provided, the function will point
          // to the first row automatically
          function nextRow()
          {
                  if ($this->getNumOfRows() > 0) {
                          $this->fields = array();
                          $this->_currentRow++;
                          $this->fields = @mssql_fetch_array($this->_queryID);
                          // This is not working.  True all the time
                          if ($this->fields) {
                                  $this->_checkAndChangeEOF($this->_currentRow - 1);
                                  return true;
                          }
                  }
                  $this->EOF = true;
                  return false;
          }

          // Returns: true on success, false on failure moveRow()
          // moves the internal row pointer of the Recordset object
          // to point to the specified row number and the data
          // corresponding to the row will be retrieved into the fields
          // collection.  If row number is not provided, the function will
          // point to the first row automatically
          function moveRow($rowNumber = 0)
          {
                  if ($rowNumber == 0) {
                          return $this->firstRow();
                  }
                  else if ($rowNumber == ($this->getNumOfRows() - 1)) {
                          return $this->lastRow();
                  }
                  if ($this->getNumOfRows() > 0 && $rowNumber < $this->getNumOfRows()) {
                          $this->fields = null;
                          $this->_currentRow = $rowNumber;
                          if(@mssql_data_seek($this->_queryID, $this->_currentRow)) {
                                  $this->fields = @mssql_fetch_array($this->_queryID);
                                  /*      This is not working.  True all the time */
                                  if ($this->fields) {
                                          // No need to call _checkAndChangeEOF() because
                                          // the possibility of moving to the last row has
                                          // been handled by the above code
                                          $this->EOF = false;
                                          return true;
                                  }
                          }
                  }
                  $this->EOF = true;
                  return false;
          }

          // Returns: true on success, false on failure firstRow() moves
          // the internal row pointer of the Recordset object to the first
          // row and the data corresponding to the row will be retrieved
          // into the fields collection
          function firstRow()
          {
                  if ($this->getNumOfRows() > 0) {
                          $this->fields = array();
                          $this->_currentRow = 0;
                          if (@mssql_data_seek($this->_queryID, $this->_currentRow)) {
                                  $this->fields = @mssql_fetch_array($this->_queryID);
                                  $this->EOF = false;
                                  /*      This is not working.  True all the time */
                                  if ($this->fields) {
                                          return true;
                                  }
                          }
                  }
                  $this->EOF = true;
                  return false;
          }

          // Returns: true on success, false on failure lastRow() moves
          // the internal row pointer of the Recordset object to the last
          // row and the data corresponding to the row will be retrieved
          // into the fields collection
          function lastRow()
          {
                  if ($this->getNumOfRows() > 0) {
                          $this->fields = array();
                          $num_of_rows = $this->getNumOfRows();
                          $this->_tempResult = @mssql_data_seek($this->_queryID, --$num_of_rows);
                          if ($this->_tempResult) {
                                  /*      $num_of_rows decemented at above        */
                                  $this->_currentRow = $num_of_rows;
                                  $this->fields = @mssql_fetch_array($this->_queryID);
                                  /*      This is not working.  True all the time */
                                  if ($this->fields) {
                                          /*      Special case for making EOF false.      */
                                          $this->EOF = false;
                                          return true;
                                  }
                          }
                  }
                  $this->EOF = true;
                  return false;
          }

          // close() only needs to be called if you are worried about using
          // too much memory while your script is running. All associated
          // result memory for the specified result identifier will
          // automatically be freed
          function close() {
                  $this->_tempResult = @mssql_free_result($this->_queryID);
                  return $this->_tempResult;
          }

          // Returns: the number of rows in a result set.  Get
          // number of rows in result
          function getNumOfRows() {
                  return $this->_numOfRows;
          }

          /*      Returns: the number of fields in a result set.
          Get number of fields in result. */
          function getNumOfFields() {
                  return $this->_numOfFields;
          }

          /*      Check and change the status of EOF.     */
          function _checkAndChangeEOF($currentRow) {
                  if ($currentRow >= ($this->_numOfRows - 1)) {
                          $this->EOF = true;
                  }
                  else {
                          $this->EOF = false;
                  }
          }
  }
  ?>
  ______________________________________________________________________

  18.  η H Sybase SQL Server DB Wrapper 

   : Joe Thong darkjoe@softhome.net Site URL:
  <http://phpdb.linuxbox.com>

  :   ͺ̽      PHP
  Ÿ̽ .  ͺ̽  phpDB  ڵ 
  ȴ.

  ȭ   'ٸ̸ '  phpDB-
  sybase.lib  ԷϽÿ.

  ______________________________________________________________________
  <?php
  /*
  Name: phpDB Sybase module
  Version: 1.02bR6
  Description: A PHP database wrapper for various database
          servers with a powerful Recordset for result data
          manipulation.  Database results are flushed
          automatically by phpDB.
  */

  // Define this module, to prevent double class declaration
  if (!defined("_PHPDB_ABSTRACT_LAYER")) {
          define("_PHPDB_ABSTRACT_LAYER", 1 );
  }
  else
          return;

  //-------------------------------
           Class Name: phpDB
  //-------------------------------
  class phpDB
  {
          /*      public variables        */
          var $version = '1.02bR6'; // Version number of phpDB
          // This variable keeps what database type is going
          // to be used.  Current supported database server
          // are MySQL, MSQL, SQL Server, and Sybase
          var $databaseType = '';
          // Specifies which database is going to be used
          var $databaseName = '';
          // The hostname of the database server, port number
          // is optional.  e.g: "db.devNation.com"
          var $hostname = '';
          var $username = '';     // to connect to the database server
          var $password = ''; // Password for the username

          // Private variables --- starts with underscore
          // An array of executed querys.  For results
          // cleanup purposes
          var $_queryIDList       = array();
          // The returned link identifier whenever a successful
          // database connection is made
          var $_connectionID      = -1;
          // A variable which was used to keep the returned last
          // error message.  The value will then returned by
          // the errorMsg() function
          var $_errorMsg = '';
          // This variable keeps the last created result
          // link identifier
          var $_queryID = -1;
          // A boolean variable to state whether its a
          // persistent connection or normal connection
          var     $_isPersistentConnection = false;
          // Holds the newly created result object, returned
          // via the execute() method
          var $_tempResultObj = '';

          // A constructor function for the phpDB object.  When
          // initializing, specify the dbType i.e: "mysql",
          // "msql", "postgresql", "mssql", and "sybase"
          function phpDB($dbType = "sybase")
          {
                  switch ($dbType) {
                          case "mysql":
                          case "msql":
                          case "postgresql":
                          case "mssql":
                          case "sybase":
                          case "informix":
                                  $this->databaseType = $dbType;
                                  break;
                          default:
                                  return false;
                  }
          }

          // Returns: A positive link identifier on success, or
          // false on error.      Connect to the server with the
          // provided arguments. The connection to the server will be
          // closed when the script terminates, unless close()
          // function is called beforehand
          function connect($argHostname = "", $argUsername = "",
                  $argPassword = "", $argDatabaseName = "")
          {
                  $boolDBSelected;
                  if ($argHostname != "") {
                          $this->hostname = $argHostname;
                  }
                  if ($argUsername != "") {
                          $this->username = $argUsername;
                  }
                  if ($argPassword != "") {
                          $this->password = $argPassword;
                  }
                  if ($argDatabaseName != "") {
                          $this->databaseName = $argDatabaseName;
                  }

                  $this->_connectionID = @sybase_connect($this->hostname, $this->username, $this->password);

                  if ($this->databaseName && $this->_connectionID) {
                          $boolDBSelected = @sybase_select_db($this->databaseName);
                          /*      If DB selection fails   */
                          if(!$boolDBSelected) {
                                  /*      Close the current connection    */
                                  @sybase_close($this->_connectionID);
                                  return false;
                          }
                  }
                  return $this->_connectionID;
          }

          // Returns: A positive link identifier on success, or false
          // on error.  Connect to the server with the provided
          // arguments. The connection to the server will not be closed
          // when the script terminates. Instead it will be kept for later future use
          function pconnect($argHostname = "", $argUsername = "",
                  $argPassword = "", $argDatabaseName = "")
          {
                  $boolDBSelected;
                  if ($argHostname != "") {
                          $this->hostname = $argHostname;
                  }
                  if ($argUsername != "") {
                          $this->username = $argUsername;
                  }
                  if ($argPassword != "") {
                          $this->password = $argPassword;
                  }
                  if ($argDatabaseName != "") {
                          $this->databaseName = $argDatabaseName;
                  }

                  $this->_connectionID = @sybase_pconnect($this->hostname, $this->username, $this->password);
                  if ($this->_connectionID) {
                          $this->_isPersistentConnection = true;
                  }

                  if ($this->databaseName && $this->_connectionID) {
                          $boolDBSelected = @sybase_select_db($this->databaseName);
                          /*      if DB selection fails   */
                          if(!$boolDBSelected) {
                                  /*      Persistent connection can't be closed   */
                                  return false;
                          }
                  }
                  return $this->_connectionID;
          }

          /*      Returns: true on success, false on error
                  Select the database name to be used     */
          function selectDB($dbName) {
                  $this->databaseName = $dbName;
                  if ($this->_connectionID) {
                          return @sybase_select_db($dbName);
                  }
                  else {
                          /*      No database selected    */
                          return false;
                  }
          }

          /*      Returns: the Recordset object disregard success or failure
                  Send the sql statement to the database server.  */
          function execute($sql = "") {
                  $this->_queryID = @sybase_query($sql, $this->_connectionID);
                  // Instantiate an object without considering whether
                  // the query return any results or not
                  $this->_tempResultObj = new Recordset($this->_queryID);
                  $this->_insertQuery($this->_queryID);
                  return $this->_tempResultObj;
          }

          /*      Returns: the last error message from previous database operation
                  Note: This function is NOT available for Sybase.        */

          function errorMsg() {
                  $this->_errorMsg = "errorMsg() is not available for Sybase";
              return $this->_errorMsg;
          }

          /*      Returns: true on success, false on failure
                  Close the database connection.  */

          function close() {
                  if ($this->_queryIDList && sizeof($this->_queryIDList > 0)) {
                          while(list($_key, $_resultID) = each($this->_queryIDList)) {
                                  @sybase_free_result($_resultID);
                          }
                  }
                  // If its not a persistent connection, then
                  // only the connection needs to be closed
                  if ($this->_isPersistentConnection != true) {
                          return @sybase_close($this->_connectionID);
                  }
                  else {
                          return true;
                  }
          }

          // A PRIVATE function used by the constructor function
          // of the query object.  insert the successful returned
          // query id to the query id list.  Used for later results
          // cleanup.  A private function that's never meant
          // to be used directly
          function _insertQuery($query_id) {
                  $this->_queryIDList[] = $query_id;
          }
  }

  //----------------------------------
           Class Name: Recordset
  //----------------------------------
  class Recordset
  {
          /*      public variables        */
          var $fields;
          // indicates that the current record position is
          // before the first record in a Recordset object
          var $BOF = null;
          // indicates that the current record position
          // is after the last record in a Recordset object
          var $EOF = null;

          // Private variables - starts with underscore
          var $_numOfRows = -1; // NEVER change the value! READ-ONLY!
          var $_numOfFields = -1; // NEVER change the value! READ-ONLY!
          // Holds anything that was returned from
          // the database specific functions
          var $_tempResult = '';
          // This variable keeps the result link identifier
          var $_queryID = -1;
          // This variable keeps the current row in the Recordset
          var $_currentRow = -1;

          // Returns: query id on success and false if
          // failed Constructor function
          function Recordset($queryID) {
                  $this->_queryID = $queryID;
                  if ($queryID) {
                          $this->_numOfRows = @sybase_num_rows($this->_queryID);
                          $this->_numOfFields = @sybase_num_fields($this->_queryID);
                  }
                  else {
                          $this->_numOfRows = 0;
                          $this->_numOfFields = 0;
                  }
                  /*      If result set contains rows     */
                  if ($this->_numOfRows > 0 && $this->_currentRow == -1) {
                          $this->_currentRow = 0;
                          $this->fields = @sybase_fetch_array($this->_queryID);
                          $this->EOF = false;
                          $this->BOF = false;
                  }
                  return $this->_queryID;
          }

          // Returns: true if successful, false if fail Set
          // the Recordset pointer to a specified field offset.
          // If the next call to fetchField() won't include a
          // field offset, this field would be returned
          function fieldSeek($fieldOffset = -1) {
                  $this->_tempResult = @sybase_field_seek($this->_queryID, $fieldOffset);
                  return $this->_tempResult;
          }

          // Returns: an object containing field information.
          // Get column information in the Recordset object.
          // fetchField() can be used in order to obtain information
          // about fields in a certain query result. If the field
          // offset isn't specified, the next field that wasn't yet
          // retrieved by fetchField() is retrieved
          function fetchField($fieldOffset = -1) {
                  if ($fieldOffset != -1) {
                          $this->_tempResult = @sybase_fetch_field($this->_queryID, $fieldOffset);
                  }
                  /*      The $fieldOffset argument is not provided thus its -1   */
                  else if ($fieldOffset == -1) {
                          $this->_tempResult = @sybase_fetch_field($this->_queryID);
                  }
                  return $this->_tempResult;
          }

          // Returns: true if there still rows available, or
          // false if there are no more rows.  Moves to the next
          // row in a specified Recordset object and makes that record
          // the current row and the data corresponding to the row will
          // be retrieved into the fields collection.  Note: Unlike
          // the moveRow() method, when _currentRow is getNumOfRows() - 1,
          // EOF will immediately be true.  If row number is not
          // provided, the function will point to the
          // first row automatically
          function nextRow() {
                  if ($this->getNumOfRows() > 0) {
                          $this->fields = array();
                          $this->_currentRow++;
                          $this->fields = @sybase_fetch_array($this->_queryID);
                          /*      This is not working.  True all the time */
                          if ($this->fields) {
                                  $this->_checkAndChangeEOF($this->_currentRow - 1);
                                  return true;
                          }
                  }
                  $this->EOF = true;
                  return false;
          }

          // Returns: true on success, false on failure moveRow()
          // moves the internal row pointer of the Recordset object
          // to point to the specified row number and the data
          // corresponding to the row will be retrieved into the
          // fields collection.  If row number is not provided, the
          // function will point to the first row automatically
          function moveRow($rowNumber = 0) {
                  if ($rowNumber == 0) {
                          return $this->firstRow();
                  }
                  else if ($rowNumber == ($this->getNumOfRows() - 1)) {
                          return $this->lastRow();
                  }
                  if ($this->getNumOfRows() > 0 && $rowNumber < $this->getNumOfRows()) {
                          $this->fields = null;
                          $this->_currentRow = $rowNumber;
                          if(@sybase_data_seek($this->_queryID, $this->_currentRow)) {
                                  $this->fields = @sybase_fetch_array($this->_queryID);
                                  /*      This is not working.  True all the time */
                                  if ($this->fields) {
                                          // No need to call _checkAndChangeEOF()
                                          // because the possibility of moving to the
                                          // last row has been handled by the above code
                                          $this->EOF = false;
                                          return true;
                                  }
                          }
                  }
                  $this->EOF = true;
                  return false;
          }

          // Returns: true on success, false on failure firstRow()
          // moves the internal row pointer of the Recordset object
          // to the first row and the data corresponding to the row
          // will be retrieved into the fields collection
          function firstRow() {
                  if ($this->getNumOfRows() > 0) {
                          $this->fields = array();
                          $this->_currentRow = 0;
                          if (@sybase_data_seek($this->_queryID, $this->_currentRow)) {
                                  $this->fields = @sybase_fetch_array($this->_queryID);
                                  $this->EOF = false;
                                  /*      This is not working.  True all the time */
                                  if ($this->fields) {
                                          return true;
                                  }
                          }
                  }
                  $this->EOF = true;
                  return false;
          }

          // Returns: true on success, false on failure lastRow()
          // moves the internal row pointer of the Recordset object
          // to the last row and the data corresponding to the row
          // will be retrieved into the fields collection
          function lastRow() {
                  if ($this->getNumOfRows() > 0) {
                          $this->fields = array();
                          $num_of_rows = $this->getNumOfRows();
                          $this->_tempResult = @sybase_data_seek($this->_queryID, --$num_of_rows);
                          if ($this->_tempResult) {
                                  /*      $num_of_rows decemented at above        */
                                  $this->_currentRow = $num_of_rows;
                                  $this->fields = @sybase_fetch_array($this->_queryID);
                                  /*      This is not working.  True all the time */
                                  if ($this->fields) {
                                          /*      Special case for making EOF false.      */
                                          $this->EOF = false;
                                          return true;
                                  }
                          }
                  }
                  $this->EOF = true;
                  return false;
          }

          // close() only needs to be called if you are worried
          // about using too much memory while your script is
          // running. All associated result memory for the
          // specified result identifier will automatically be freed
          function close() {
                  $this->_tempResult = @sybase_free_result($this->_queryID);
                  return $this->_tempResult;
          }

          /*      Returns: the number of rows in a result set.
          Get number of rows in result.   */

          function getNumOfRows() {
                  return $this->_numOfRows;
          }

          /*      Returns: the number of fields in a result set.
          Get number of fields in result. */

          function getNumOfFields() {
                  return $this->_numOfFields;
          }

          /*      Check and change the status of EOF.     */
          function _checkAndChangeEOF($currentRow) {
                  if ($currentRow >= ($this->_numOfRows - 1)) {
                          $this->EOF = true;
                  }
                  else {
                          $this->EOF = false;
                  }
          }
  }
  ?>
  ______________________________________________________________________

  19.  η I phpDB.inc 

   : Joe Thong darkjoe@softhome.net Site URL:
  <http://phpdb.linuxbox.com>

  Description:   ͺ̽     
  PHP Ÿ̽ .  ͺ̽  phpDB  ڵ
   ȴ.

  ȭ   'ٸ̸ ' 
  phpDB.inc  ԷϽÿ.

  ______________________________________________________________________
  <?php
  /*
  Name: phpDB General module
  Version: 1.02bR6
  Description: A PHP database wrapper for various
          database servers.  Database results are flushed
          automatically by phpDB.  Supported database
          servers are MySQL, MSQL, PostgreSQL, Microsoft
          SQL Server and Sybase.
  */

          if (!defined("_PHPDB_GENERAL_LAYER")) {
            define("_PHPDB_GENERAL_LAYER", 1 );
          }
          else
                  return;

          // Fill in the database server that you're
          // going to use.  Consult the phpDB Reference
          // Manual for more information
          $databaseType = '';
          // The phpDB module root path.  No trailing slash
          $phpDBRootPath = '.';

          function useDB($dbType = "")
          {
                  GLOBAL $phpDBRootPath;
                  switch (strtolower($dbType))
                  {
                          case "mysql":
                          case "msql":
                          case "postgresql":
                          case "mssql":
                          case "sybase":
                          case "informix":
                                  include("$phpDBRootPath". "/phpDB-" . "$dbType.lib");
                                  break;
                          case "":
                                  die("Please edit phpDB.inc in order to use phpDB");
                                  return false;
                          default:
                                  die("Invalid database selection");
                                  return false;
                  }
                  return true;
          }

          useDB($databaseType);
  ?>
  ______________________________________________________________________

  20.  η J phpDBTest.php3 

   : Joe Thong darkjoe@softhome.net Site URL:
  <http://phpdb.linuxbox.com>

  :   ͺ̽      PHP
  Ÿ̽ .  ͺ̽  phpDB  ڵ 
  ȴ.

  ȭ   'ٸ̸ '  phpDB-
  mssql.lib  ԷϽÿ.(: phpDB-mssql.lib  ƴϰ.
  phpDBTest.php3 ؾմϴ.)
  ______________________________________________________________________
  <html>
  < head>
          < title>Untitled< /title>
  < /head>

  < body>
  <?php
          // ȭ phpDB.inc ִ 丮 ִٰ մϴ.
          include("phpDB.inc");
          $db = new phpDB();
          $db->pconnect("hostName", "userName", "passWord", "databaseName") or die ("Can't connect to database server or select database");
          $rs = $db->execute("SELECT * FROM Items");
          $numOfRows = $rs->getNumOfRows();
          echo "Number of Rows: $numOfRows";

          $rs->firstRow(); // û̳, õմϴ.
          while (!$rs->EOF) {
                  // Fields collection accessible as associative arrays too
                  echo "<br>" . $rs->fields[0];
                  $rs->nextRow(); // NOTE: nextRow() is placed at below
          }

          $rs->close();
          $db->close();   // û
  ?>
  < /body>
  < /html>
  ______________________________________________________________________

