0
I am using Multiple Insert, but the internal characters of the text have caused Insert to fail. I used the addslaches method in the string but the error remains, some hint of what I can do to circumvent?
I have the following code
private function GetPostsNews($token,$secret,$fields)
{
$this->pack = json_decode($this->getToken($token,$secret,$fields), true);
if(count($this->pack)<25)
{$updated = 0;}
else{$updated=1;}
foreach($this->pack as $key => $value):
if(!isset($value['picture'])) : $value['picture'] = 'imagem/post.jpg' ; endif ;
if(!isset($value['message'])) : $value['message'] = 'imagem incorporada' ; endif ;
if(!isset($value['permalink_url'])) : $value['permalink_url'] = 'not a link set' ; endif ;
if(!isset($value['name'])) : $value['name'] = 'not a name set' ; endif ;
$idpost = $value['id'];
$ps_idpage = $this->guide[0];
$ps_date = \TimeConver::GMTtoUTC($value['created_time']['date'], "Y-m-d H:i:s");
$ps_categoty = $value['type'];
$ps_picture = $value['picture'];
$ps_name = $value['name'];
$ps_message = addslashes($value['message']);
$ps_link = $value['permalink_url'];
$sent = new \sentimentalization($idpost,$ps_date,'FB_POST',$ps_message);
$wordcloud = new \wordcloud($idpost,'FB_POST',$ps_message);
$this->values.= "('{$idpost}','{$ps_idpage}','{$ps_date}','{$ps_categoty}','{$ps_picture}','{$ps_name}','{$ps_message}','{$ps_link}'), " ;
$ps = new Executor();
$ps->PostSummary($idpost)->CollectPostSummary();
endforeach;
$insert = new \insert();
$insert->InsertMultiplePost($this->values);
ai in the CRUD have
public function insertmultiple($fields,$values){
// Atribui a instrução SQL construida no método
$sql = $this->buildInsertMultiple($fields, $values);
// Passa a instrução para o PDO
$stm = $this->pdo->prepare($sql);
// Executa a instrução SQL e captura o retorno
$retorno = $stm->execute();}
and
private function buildInsertmultiple($campos, $values){
// Inicializa variáveis
//$sql = "";
//$campos = "";
//$valores = "";
// Loop para montar a instrução com os campos e valores
// Retira vírgula do final da string
// Retira vírgula do final da string
$values = (substr($values, -2) == ', ') ? trim(substr($values, 0, (strlen($values) - 2))) : $values ;
// Concatena todas as variáveis e finaliza a instrução
$sql = "INSERT INTO {$this->tabela}" . $campos . "VALUES" . $values ;
var_dump($sql);
// Retorna string com instrução SQL
return trim($sql);
}
the log returns me the following error: < 2016-08-22 12:03:55.490 BRT >ERROR: syntax error at or near "O" at Character 148 < 2016-08-22 12:03:55.490 BRT >STATEMENT: INSERT INTO reduce_word_recurrency(_id, rwr_id, rwr_type,rwr_word) VALUES('201608221208580.090165' , '109597815616_10154194837525617','FB_POST',' 'O' ), ('201608221208$ < 2016-08-22 12:03:56.439 BRT >ERROR: syntax error at or near "no" at Character 1045 < 2016-08-22 12:03:56.439 BRT >STATEMENT: INSERT INTO reduce_word_recurrency(_id, rwr_id, rwr_type,rwr_word) VALUES('201608221208590.038443' , '109597815616_101541917860617','FB_POST','Journal' ), ('201608221$ < 2016-08-22 12:04:12.461 BRT >ERROR: syntax error at or near "Com" at Character 1648 < 2016-08-22 12:04:12.461 BRT >STATEMENT: INSERT INTO fb_post(idpost,ps_idpage,ps_date,ps_categoty,ps_picture,ps_name,ps_message,ps_link)VALUES(....
Christopher, please edit your question, including the code you already have so we can assist you in the best way possible.
– Bruno Bermann
I put Bruno Bermann what I’ve been using in the classes, thank you!
– Christopher Tavares