Hi fellas,
My Function:
public function Atualiza( $colunas==array() ){
//get the array keys and turn into string
$chaves = implode(",",array_keys($colunas));
//turn the string into array
$chaves = explode(",", $chaves);
//get the array values and turn into string
$valores = implode(",",array_values($colunas));
//turn the string into array
$valores = explode(",",$valores);
$qtd = sizeof($colunas);
for($x=0;$x<$qtd;$x++){
$campo[] = $chaves[$x]."='".$valores[$x]."'";
}
$update = implode(", ",$campo);
$sql = "UPDATE ".$this->nomeClasse." SET ".$update
}
The function will return a SQL statement like “UPDATE user SET name=‘paul’, email=‘paul@sitepoint.com.br’, password=‘123’, description=‘Aenean suscipit pulvinar felis, vitae luctus nulla viverra quis.’”
The problem is with my array commands and the description field. The description field will receive a text and it may contain commas, what will make my array_values totally useless and return a wrong statement because the array_values will implode in the first comma of the descrition field.
Get it?
Sorry for any typos and any confusion!
And if possible, any ideas to make this function better?
Thanks in advance;)