Ver Mensaje Individual
  #5 (permalink)  
Antiguo 31/03/2014, 12:50
Avatar de JAK^
JAK^
 
Fecha de Ingreso: octubre-2005
Ubicación: ^^CaMiNiTo Al CoSTaDo DeL
Mensajes: 850
Antigüedad: 18 años, 6 meses
Puntos: 4
Respuesta: extraño problema con insert

este es el codigo que faltaba publicar, el que genera el sql.. en fin.. a mi entender no hay error. no se por que se puede comportar asi el codigo solo con el valor 1

Código PHP:
Ver original
  1. class Sql
  2. {
  3.     private $_where = array ();
  4.     private $_order = array ();
  5.     private $_select = array ();
  6.     private $_from = array ();
  7.     private $_funcion;  
  8.     private $_values = array();
  9.    
  10.  
  11.     public function getSQL()
  12.     {
  13.       return $this->_funcion;
  14.   }
  15.    
  16.     public function addTabla ($tabla)
  17.     {
  18.         $this -> _from[]=$tabla;
  19.     }
  20.     public function addSelect ($select)
  21.     {
  22.        
  23.             $this -> _select []=$select;
  24.        
  25.     }
  26.     public function addWhere ($where)
  27.     {
  28.         $this -> _where []= $where;
  29.     }
  30.    
  31.     public function addOrder ($order)
  32.     {
  33.         $this -> _order []= $order;
  34.     }
  35.    
  36.     public function addFuncion ($funcion)
  37.     {
  38.         $this -> _funcion = $funcion;
  39.     }
  40.    
  41.     public function addValue($value)
  42.     {
  43.       $this->_values[] = $value;
  44.     }
  45.    
  46.    
  47.    
  48.     private function _generar()
  49.     {
  50.        
  51.         $select = implode(', ',array_unique($this->_select));
  52.         $values = implode("','",array_unique($this->_values));
  53.         $from   = implode(', ',array_unique($this->_from));
  54.         $where  = implode(' AND ',array_unique($this->_where));
  55.         $order  = implode(', ',array_unique($this->_order));
  56.         $table = implode(', ',array_unique($this->_from));
  57.         $funcion = strtolower($this->_funcion);
  58.        
  59.         $select_format = "SELECT %s FROM %s WHERE %s ORDER BY %s DESC";
  60.         $select_format_sw = "SELECT %s FROM %s ORDER BY %s DESC";
  61.         $select_format_g = "SELECT %s FROM %s  WHERE %s ORDER BY %s DESC";
  62.         $insert_format = "INSERT INTO %s (%s) VALUES ('%s')";
  63.         $delete_format = "DELETE FROM %s WHERE %s";
  64.         $update_format = "UPDATE %s SET %s WHERE %s";
  65.        
  66.        
  67.         switch ($funcion) {
  68.             case 'select_sw':
  69.                 return sprintf($select_format_sw, $select, $from, $order);
  70.             break;
  71.             case 'select':
  72.                 return sprintf($select_format, $select, $from, $where, $order);
  73.             break;
  74.             case 'insert':
  75.                 return sprintf($insert_format, $table, $select, $values);
  76.             break;
  77.             case 'delete':
  78.                 return sprintf($delete_format, $from, $where);
  79.             break;
  80.             case 'update':
  81.                 return sprintf($update_format, $table, $select, $where);
  82.             break;
  83.             case 'select_g':
  84.                
  85.                 return sprintf($select_format_g, $select, $table,  $where, $order);
  86.             break;
  87.             default :
  88.                 return sprintf($select_format, '*', $from, $where);
  89.             break;
  90.         }  
  91.     }
  92.    
  93.     public function __toString()
  94.     {
  95.         return $this->_generar();
  96.     }
  97. }
__________________
hola . . .