1
I’m trying to record a result of a query
in a json_encode
and right after recording in a field in my BD
, but I am getting an error message and could not solve the problem.
What am I doing:
$IdUsuario = $rowData['IdUsuario'];
// RECUPERANDO DADOS
$queryResult = array();
$this->GetConnection()->ExecQueryToArray('SELECT * FROM cadUsuario WHERE cadUsuario.IdUsuario = ' . $IdUsuario, $queryResult);
$string = json_encode($queryResult);
// INSERINDO DADOS DO ITEM LOG
$IdUsuario = $this->GetEnvVar('CURRENT_USER_ID');
// INSERINDO DADOS DA TABELA DE LogItens
$this->GetConnection()->ExecSQL('INSERT INTO cadLogItem (IdLog, Operacao, DataHoraOcorrencia, IdUsuario, Instancia) VALUES ('.$IdLog.', "AT", CURRENT_TIMESTAMP, '.$IdUsuario.', '.$string.' )');
And the error message is this:
Cannot execute SQL statement: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[{"0":"26","IdUsuario":"26","1":"[email protected]","Email":"carolmerigue' at line 1
The field in the comic book is in the format MediumText
.
If it’s a string, no quotation marks in SQL?
– Woss
Hello @Andersoncarloswoss, quote -> '.$string.'
– adventistapr
These are just to concatenate. Inside SQL there will be no quotes. Just debug your code to understand the problem.
– Woss
of an echo in
$string
. And show the result. I wonder what the problem is.– Andrei Coelho