I'm trying to insert therms in a database using the exec
function from the PHP's SQLite3 library and I'm having problems with strings:
foreach($xml->children() as $child) {
$id = 0;
$nome = "null";
$partido = "null";
$tag_localizacao = 0;
foreach ($child->children() as $grandchild) {
switch($grandchild->getName()) {
case "id":
$id = $grandchild;
break;
case "nome":
$nome = $grandchild;
break;
case "partido":
$partido = $grandchild;
break;
case "tagLocalizacao":
$tag_localizacao = $grandchild;
}
}
$db->exec('INSERT INTO lista_deputados (id, nome, partido, tag_localizacao) VALUES ('.$id.','.$nome.', '.$partido.', '.$tag_localizacao.')');
}
$id
and $tag_localizacao
are integers, and it works perfectly. $nome
and $partido
are strings and don't work at all... when the string has just one word, like "test" the PHP thinks that it's a column and if has more words i don't know exactly what happens but the error message is:
Warning: SQLite3::exec(): near "Lopes": syntax error in C:\wamp\www\desafio\temp.php on line 30
In the case the string is "Adalclever Lopes".
I'm really not understanding what is happening, and I even tried to escape the string.