Este es mi siguiente php que almacena la clase.
<?php
class query{
var $tip;
var $param;
var $value;
var $param_if;
var $value_if;
var $limit_param;
var $limit_value;
var $limit_param_if;
var $limit_value_if;
var $tabla;
var $consulta_string;
var $where_string;
function onQuery($tip_new){
$local = "localhost";
$root = "root";
$pass = "";
$db = "query";
mysql_connect($local, $root, $pass);
mysql_select_db($db);
$this->tip = $tip_new[0];
$this->tabla = $tip_new[1];
$this->param = $tip_new[2];
$this->value = $tip_new[3];
$this->param_if = $tip_new[4];
$this->value_if = $tip_new[5];
$this->limit_param = count($tip_new[2]);
$this->limit_value = count($tip_new[3]);
$this->limit_param_if = count($tip_new[4]);
$this->limit_value_if = count($tip_new[5]);
switch($this->tip){
case "insert":
if(($this->limit_param==$this->limit_value)){
function onGeneraConsult($tabla, $string){
$consulta = "INSERT INTO ".$tabla." SET ".$string."";
$res = mysql_query($consulta);
}
$array_value_consult = array();
for($i=0;$i<$this->limit_param;$i++){
$array_value_consult[$i] = $this->param[$i]."='".ucfirst(strtolower($this->value[$i]))."'";
if($i==(($this->limit_param)-1)){
$this->consulta_string = implode(", ", $array_value_consult);
onGeneraConsult($this->tabla, $this->consulta_string);
}
}
}else{
echo "Error.";
}
break;
case "delete":
if(($this->limit_param==$this->limit_value)){
function onGeneraConsult($tabla, $string){
$consulta = "DELETE FROM ".$tabla." WHERE ".$string."";
$res = mysql_query($consulta);
}
$array_value_consult = array();
for($i=0;$i<$this->limit_param;$i++){
$array_value_consult[$i] = $this->param[$i]."='".ucfirst(strtolower($this->value[$i]))."'";
if($i==(($this->limit_param)-1)){
$this->consulta_string = implode(" AND ", $array_value_consult);
onGeneraConsult($this->tabla, $this->consulta_string);
}
}
}else{
echo "Error.";
}
break;
case "update":
if(($this->limit_param==$this->limit_value)){
function onGeneraConsult($tabla, $string, $string_if){
$consulta = "UPDATE ".$tabla." SET ".$string." WHERE ".$string_if."";
$res = mysql_query($consulta);
}
$array_value_consult = array();
$array_value_if = array();
for($i=0;$i<$this->limit_param;$i++){
$array_value_consult[$i] = $this->param[$i]."='".ucfirst(strtolower($this->value[$i]))."'";
if($i==(($this->limit_param)-1)){
$this->consulta_string = implode(", ", $array_value_consult);
for($n=0;$n<$this->limit_param_if;$n++){
$array_value_if[$n] = $this->param_if[$n]."='".ucfirst(strtolower($this->value_if[$n]))."'";
if($n==(($this->limit_param_if)-1)){
$this->where_string = implode(" ADN ", $array_value_if);
onGeneraConsult($this->tabla, $this->consulta_string, $this->where_string);
}
}
}
}
}else{
echo "Error.";
}
break;
case "select":
if(($this->limit_param!=$this->limit_value)){
function onGeneraConsult($tabla, $string, $string_if){
$consulta = "SELECT ".$string." FROM ".$tabla." WHERE ".$string_if."";
$res = mysql_query($consulta);
}
$array_value_consult = array();
$array_value_if = array();
for($i=0;$i<$this->limit_param;$i++){
$array_value_consult[$i] = $this->param[$i];
if($i==(($this->limit_param)-1)){
$this->consulta_string = implode(", ", $array_value_consult);
for($n=0;$n<$this->limit_param_if;$n++){
$array_value_if[$n] = $this->param_if[$n]."='".ucfirst(strtolower($this->value_if[$n]))."'";
if($n==(($this->limit_param_if)-1)){
$this->where_string = implode(" ADN ", $array_value_if);
onGeneraConsult($this->tabla, $this->consulta_string, $this->where_string);
}
}
}
}
}else{
echo "Error.";
}
break;
}
}
}
?>
La clase me anda exelente Tiene INSERT, DELETE, UPDATE, Y SELECT.
La uso de la siguiente forma.
Insert EJ:
$par = array("nombre", "apellido", "id");
$val = array("gonzalo", "telesio", "1");
$par_if = array();
$val_if = array();
$param = array("select", "data", $par, $val, $par_if, $val_if);
$obj = new query;
$obj->onQuery($param);
Espero me ayuden a mejorar la parte de seguridad de esta clase para que la consulta que se ejecute no pueda ser injectable.
Gracias desde ya.