Well I'm with an 'X' object that one of its properties is a JSON. In this JSON it contains the column name and column value respectively.
But I can have several 'X' objects, and so on. Today I'm doing it as follows:
PHP:
public function SincronizaBanco_MobileWeb(array $params = NULL) {
$objeto = json_decode($this->params['objJSON']);
$tamanho = count($objeto);
try {
for ($i = 0; $i < $tamanho; $i++) {
if ($objeto[$i]->FLG_IDENT_OPERA == 'I') {
$inputs = array();
$inputsJSON = $objeto[$i]->TXT_COLUN_SINCR;
$inputs[':values'] = json_decode($inputsJSON);
print_r($inputs);
$sincronismo = $this->conexao->save("INSERT INTO " + $objeto[$i]->TXT_TABLE_SINCR + " values (:values);", $inputs);
} else if ($objeto[$i]->FLG_IDENT_OPERA == 'U') {
} else {
}
}
print_r("Inserção concluido com sucesso !");
} catch (Exception $exc) {
echo $exc->getTraceAsString();
}
}
}
You are giving the following error:
[Sat Dec 05 09:22:57 2015] [error] [client 192.168.1.248] PHP Catchable fatal error: Object of class stdClass could not be converted to string in / opt / lampp / htdocs / renan / connection. php on line 53, referer: link
The error occurs in the following function:
public function execute(PDOStatement $stmt, array $data = null) {
try {
if (isset($data)) {
$stmt->execute($data);
} else {
$stmt->execute();
}
} catch (PDOException $exc) {
echo $exc->getTraceAsString();
var_dump($exc->getMessage());
}
}
And what calls this function is
public function save($sql, array $data) {
$con = self::getConnection();
$stmt = $con->prepare($sql);
print_r($stmt);
$this->execute($stmt, $data);
if ($stmt->rowCount()) {
return true;
} else {
return false;
}
}
How do I resolve this?
My array after json_decode looks like this:
Array
(
[0] => stdClass Object
(
[COD_IDENT_SINCR] => 1
[TXT_TABLE_SINCR] => tbl_PESSOAS
[FLG_IDENT_OPERA] => I
[TXT_COLUN_SINCR] => {"COD_IDENT_PESSO":"1151205091356692","TXT_NOMEX_PESSO":"iyuiyui","TXT_APELI_PESSO":"yuiyuiy","FLG_SEXOX_PESSO":"","DAT_NASCI_PESSO":"","TXT_NASCI_PESSO":"","TXT_NATUR_PESSO":"","FLG_ESTAD_CIVIL":"S","TXT_FONEX_PESSO":"","FLG_IDENT_PESSO":"A","TXT_EMAIL_PESSO":"","TXT_SENHA_PESSO":"","TXT_ENDER_CEPXX":"","TXT_ENDER_LOGRA":"","TXT_ENDER_BAIRR":"","TXT_ENDER_NUMER":"","TXT_ENDER_COMPL":""}
[TXT_WHERE_SINCR] =>
[FLG_IDENT_SINCR] => N
[COD_IDULT_ATUAL] => -1
[DAT_ULTIM_ATUAL] => 2015-11-05 09:13:56
)
[1] => stdClass Object
(
[COD_IDENT_SINCR] => 2
[TXT_TABLE_SINCR] => tbl_PESSOA_TURMA
[FLG_IDENT_OPERA] => I
[TXT_COLUN_SINCR] => {"COD_IDENT_PESSO":"1151205091356692","COD_IDENT_CELUL":"1","FLG_IDENT_PESSO":"M","COD_IDULT_ATUAL":"-1","DAT_ULTIM_ATUAL":"2015-11-05 09:13:56"}
[TXT_WHERE_SINCR] =>
[FLG_IDENT_SINCR] => N
[COD_IDULT_ATUAL] => -1
[DAT_ULTIM_ATUAL] => 2015-11-05 09:13:56
)
)