My Perl Libs


NAME

     EL::sql - User Friendly API abstration to Mysql access


SYNOPSIS

     use EL::sql;
     my $sql = EL::session->new;


DESCRIPTION

     A user friendly API abstration to Mysql access. This complements the
 libs  EL::cgi and  EL::sql  allowing creation  of  web aplications  with
 suport  the SGBD  (in  moment  Mysql). Help  to  addition  new SGBDs  is
 welcome!

METHODS

     $sql->connect($host,$bd,$user,$password)
     Establishes connection with SGBD in  host `$host', selects data base
     `$bd' and is identified by user `$user' and password `$password'.
     
     $sql->query($statement)
     $sql->query($statement,$id)
     Submit a query and optionally identifies it by `$id'.
     
     $sql->fetchhash
     $sql->fetchhash($id)
     Fetch next  row of  data from  the statement  or from  the statement
     identified by `$id' and return it  in a hash struct reference. Where
     col names of tables will are the keys in hash.
     
     $sql->fetcharray
     $sql->fetcharray($id)
     Fetch next  row of  data from  the statement  or from  the statement
     identified by `$id' and return it in a array struct reference.
     $sql->fetchrow
     $sql->fetchrow($id)
     Fetch next  row of  data from  the statement  or from  the statement
     identified by `$id' and return it in a array struct.
     
     $sql->numrows
     $sql->numrows($id)
     
     Get the number rows of data from the statment.
     
     
     $sql->insertid
     $sql->insertid($id)
     In 'INSERT'  statement return  the value  of 'autoincrement'  col in
     table.


EXAMPLE

     -- PERL FILE: search.pl
     
     use strict;
     use EL::sql;
     use EL::cgi;
     my $cgi = EL::cgi->new;
     my $sql = EL::sql->new;
     if ($cgi->get('name')) {
         $sql->connect($host,$bd,$user,$passwd);
         
         $sql->query("SELECT * FROM client WHERE name='$cgi->get('name')'",'cli');
         $sql->query("SELECT * FROM supplier WHERE name='$cgi->get('name')'");
         my @arr;
         # Fetch data client
         while (my $hsh = $sql->fetchhash('cli')) {
             push @arr,$hsh;
         }
         $cgi->set('clients',\@arr) if @arr;
         @arr = ();
         
         # Fetch data supplier
         while (my $hsh = $sql->fetchhash) {
             push @arr,$hsh;
         }
         $cgi->set('supplier',\@arr) if @arr;
     }
     $cgi->out('search.html');
     
     -- TEMPLATE FILE: search.html
     <html>
         <body>
             <form action="search.pl" method="post">
             <table>
                 <tr>
                     <td>
                         Name (client/supplier):
                     </td>
                     <td>
                         <input type="text" name="name">
                     </td>
                 </tr>
              </table>
              <TMPL_IF client>
              <table>
                 <tr>
                     <th colspan="3">
                         CLIENTS
                     </th>
                 </tr>
                 <tr>
                     <th>
                         Name
                     </th>
                     <th>
                         E-mail
                     </th>
                     <th>
                         Phone
                     </th>
                 </tr>
                 <TMPL_LOOP client>
                 <tr>
                 <tr>
                     <td>
                         <TMPL_VAR name>
                     </td>
                     <td>
                         <TMPL_VAR email>
                     </td>
                     <td>
                         <TMPL_VAR phone>
                     </td>
                 </tr>
                 </TMPL_LOOP>
              </table>
              </TMPL_IF>
                 
              <TMPL_IF supplier>
              <table>
                 <tr>
                     <th colspan="3">
                         SUPPLIERS
                     </th>
                 </tr>
                 <tr>
                     <th>
                         Name
                     </th>
                     <th>
                         E-mail
                     </th>
                     <th>
                         Phone
                     </th>
                 </tr>
                 <TMPL_LOOP supplier>
                 <tr>
                     <td>
                         <TMPL_VAR name>
                     </td>
                     <td>
                         <TMPL_VAR email>
                     </td>
                     <td>
                         <TMPL_VAR phone>
                     </td>
                 </tr>
                 </TMPL_LOOP>
              </table>
              </TMPL_IF>
           
           </form>
        </body>
     </html>


AUTHORS

     Ednardo Lobo <ednardo@elobo.cjb.net>


SEE ALSO

     EL::lib, DBI