We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

SQLSTATE[42000]:Syntax error or access violation

I am not able to execute an insert statement....when i am trying to run an sql statement i am getting this error.....SQLSTATE[42000]: Syntax error or access violation: 1064 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 'entry '55555576' for key 'emp_corp_id')' at line 1

foreach ($err_array as $key => $record) {
    $data[] = [
        'id' => $key,
        'name' => $record[0],
        'username' => $record[1],
        'mdn' => $record[3],
        'employeeCorporateID' => $record[4],
        'department' => $record[5],
        'band' => $record[6],
        'date' => $record[7],
        'errors' => $record[8],
    ];
    $this->db->execute(
            "INSERT INTO `temporary2` (id,name,username,mdn,employeeCorporateID,department,band,date,errors)  VALUES ($key,$record[0],$record[1],$record[3],$record[4],$record[5],$record[6],$record[7],$record[8]);"
    );
}


85.5k

INSERT INTO `temporary2` (id,name,username,[mdn],employeeCorporateID,department,band,[date],[errors])...


12.8k
Accepted
answer

you need to escape the string parameters cause you're not bind them.