View Single Post
Old 10-15-2008, 09:52 PM   #1 (permalink)
jcorradino
The Contributor
 
jcorradino's Avatar
 
Join Date: Sep 2008
Posts: 36
Thanks: 2
jcorradino is on a distinguished road
Default A little bit of code that needs critiquing

what do you guys think:

PHP Code:
class sql {
   var 
$host   =   'host';
   var 
$user   =   'username';
   var 
$pass   =   'password';
   var 
$db     =   'database';
   var 
$link;
   var 
$sql;
   var 
$result;
   var 
$nl '
'
;
   function 
__construct($sql$format=''$ele1$ele2=null$ele3=null$ele4=null$ele5=null$ele6=null$ele7=null$ele8=null$ele9=null$ele10=null) {
      if (
strchr($sql,'auto-')) {$newsql='SELECT * FROM '.str_replace('auto-','',$sql);}
      else {
$newsql=$sql;}
      if (!
strchr($format,'::1')) {$newformat='<div class="'.$format.'">::1</div>';}
      else {
$newformat=$format;}
      
self::li($newsql$newformat$ele1$ele2$ele3$ele4$ele5$ele6$ele7$ele8$ele9$ele10);
   }
   function 
co() {# Connect to database
      
$this->link mySQLi_Connect($this->host$this->user$this->pass$this->db);
      if (!
$this->link) {die();}
   }
   function 
cl() {mySQLi_Close($this->link);} #close database connection
   
function q() { #preform query on database
      
self::co();
      
$this->result=mySQLi_Query($this->link,$this->sql);
      
self::cl();
   }
   function 
li($sql$format$ele1$ele2=null$ele3=null$ele4=null$ele5=null$ele6=null$ele7=null$ele8=null$ele9=null$ele10=null) {
      
$max=1;
      for (
$i=2;$i<=10;$i++) {
         if (${
'ele'.$i}==null){break;}
         else{
$max=$i;}
      }
      
$this->sql $sql;
      
self::q();
      while (
$row mySQLi_Fetch_Assoc($this->result)) {
         
$fin $format;
         for (
$i=1;$i<=$max;$i++) {
            
$fin=Str_Replace('::'.$i,$row[${'ele'.$i}],$fin);
         } 
         echo 
$fin.$this->nl;
      }
   }
}

function 
sql($e1$e2$e3$e4=null$e5=null$e6=null$e7=null$e8=null$e9=null$e10=null$e11=null$e12=null) {
   new 
sql ($e1,$e2,$e3,$e4,$e5,$e6,$e7,$e8,$e9,$e10,$e11,$e12);

description here: Sql.Class
__________________
Jason Corradino
Applications Developer, Interactive Support - Tribune Technology
J2EE Development, Script Tinkering - Develop, Support, and Maintain Tribune websites.
jcorradino is offline  
Reply With Quote