Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

insert in phql

I try to execute this:

$sql = "INSERT INTO Malware (md5, sha1, AV, time, upload, result)  VALUES 

    ('".$md5."', '".$sha1."', '".$av."', '".$time."', '".$data."', '".$result."'),
    ('".$md5."', '".$sha1."', '".$av1."', '".$time."', '".$data."', '".$result1."'), 
    ('".$md5."', '".$sha1."', '".$av2."', '".$time."', '".$data."', '".$result2."')";

    $query = $this->modelsManager->createQuery($sql);

      $items = $query->execute();

i get this error:

Syntax error, unexpected token COMMA, near to ' ('

Any help, please ?



5.9k
Accepted
answer

Can you post $sql ?

Also you should be using prepared parameters to protected against SQL injection, ie.

$sql = "INSERT INTO Malware (md5, sha1, AV, time, upload, result)  VALUES 
(:md5:, :sha1:, :av:, :time:, :data:, :result:),
(:md5:, :sha1:, :av1:, :time:, :data:, :result1:),
(:md5:, :sha1:, :av2:, :time:, :data:, :result2:);"

$query = $this->modelsManager->createQuery($sql, ['md5' => $md5, 'sha1' => $sha1, 'av' => $av, 'time' => $time, 'data' => $data, 'result' => $result, 'av1' => $av1, 'result1' => $result1, 'av2' => $av2, 'result2' => $result2]);
$items = $query->execute();

You can setup an event against the DB service, or use MySQL general logging to see what the generated query being executed is for further debugging.