Syntax for RETURN clause in Mysql PDO

I am trying to add a record and at the same time return the identifier of this record. I read that this can be done with a sentence RETURNING.

$stmt->prepare("INSERT INTO tablename (field1, field2) 
                               VALUES (:value1, :value2)
                          RETURNING id");

but the insertion fails when I add RETURNING. A field auto-incrementedcalled is added to the table id.

Can someone see something wrong with my syntax? or PDO does not support RETURNING?

+3
source share
1 answer

I do not think that this is due to PDO support or not. RETURNINGsupported by Oracle and PostgreSQL, but not MySQL.

PDO::lastInsertId .

+7

Source: https://habr.com/ru/post/1744647/


All Articles