douzongmu2543
douzongmu2543
2012-10-14 18:17
浏览 14
已采纳

PDO返回新的ID错误

My question today is that I'm trying to return an id after I inserted a new line into my DB.

    $sql = ('INSERT INTO `tSections`(`sSection`, `pCity_id`) VALUES (:sSection, :pCity_id) RETURNING pSection_id');  
$new_section = $DBH->prepare($sql);

Without the returning pSection_id it works fine. Any ideas or solution. I'm assuming that I just forgot something simple.

Hope to hear from you guys soon.

This is the error that it gives

Uncaught exception 'PDOException' with message '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 'RETURNING pJob_Type_id' at line 1' in

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dquoj04882
    dquoj04882 2012-10-14 18:21
    已采纳

    There's no such thing as RETURNING in MySQL.

    You're looking for PDO::lastInsertID().

    点赞 评论

相关推荐