F
F
Freud's cat2019-05-10 22:29:04
PostgreSQL
Freud's cat, 2019-05-10 22:29:04

PDO exception number 42601, how to fix?

Good evening. There is an expression:

$this->insertStmt = $this->connection->getPdo()->prepare("
    INSERT INTO files (
           real_name, 
           virtual_name, 
           album,
           size,
           resolution, 
           duration, 
           comment,
           path,
           user
    ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
");

Which is called as usual:
protected function doInsert(object $object)
{
    $values = [
        $object->getRealName(),
        $object->getVirtualName(),
        $object->getAlbum(),
        $object->getSize(),
        $object->getResolution(),
        $object->getDuration(),
        $object->getComment(),
        $object->getPath(),
        $object->getUser(),
    ];
       
    $this->insertStmt->execute($values);
}

Sample contents of $values:
array(9) { 
    [0]=> string(15) "BvrK9z6UPxY.jpg" 
    [1]=> string(16) "1265dde1c67abc1c" 
    [2]=> string(23) "По умолчанию" 
    [3]=> int(54973) 
    [4]=> string(7) "720x430" 
    [5]=> NULL 
    [6]=> string(0) "" 
    [7]=> string(108) "files/id5cd487313a93a/По умолчанию/2019-05-10/1265dde1c67abc1c.jpg" 
    [8]=> string(15) "id5cd487313a93a" 
}

Error message:
Type: PDOException
Code: 42601
Message: SQLSTATE[42601]: Syntax error: 7 ОШИБКА: ошибка синтаксиса (примерное положение: "user") LINE 11: user ^

From the point of view of syntax, everything seems to be correct, I double-checked it many times, the IDE does not swear at anything. What's wrong, gentlemen?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2019-05-10
@medbrat69

The DBMS unequivocally answers that it does not agree with the syntax.
If you do not read the lists of reserved words - then yes, it may not be entirely obvious why this query is syntactically incorrect. But nevertheless, the word user is still reserved by both the SQL standards and the specific implementation in postgresql. Therefore, it cannot be used as an unquoted identifier .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question