I have code like this:
require 'mysql2'
@db.query("insert into clients (Name) values ('#{client}')")
Can I return last inserted id with 1 query?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
last_idmethod of the client instance:http://rubydoc.info/gems/mysql2/0.2.6/Mysql2/Client:last_id
Edit: it doesn’t answer your original question but still looks better than call for LAST_INSERT_ID