4

I tried to search an answer to this question but I couldn't really find it. I have a new value object that is partially filled which I want to insert into the database.

When the insert was succesfull I want to return the value object again back to the client side (a Flex application in my case). The reason I want this is to have the auto increment value for the id of the value object.

I thought I could use the fetchAll method again, but apparently that gives a general error incase of update/insert queries. So what is the correct way to return an updated value object back?

Kind regards, Rick

Wubinator
  • 741
  • 1
  • 7
  • 16

2 Answers2

1

If you want get only ID inserted query, you can use lastInsertId() function of PDO. http://php.net/manual/en/pdo.lastinsertid.php

Daniel
  • 350
  • 4
  • 12
  • Thanks that seems to be the answer. I should have been able to find that ..... still thanks :) – Wubinator Jul 06 '15 at 09:28
  • And what if I need not only ID, but some other fields which are filled during inserting? I.e. "insert_date" with default `NOW()` in mysql? – The Godfather Mar 31 '19 at 18:27
-1

for last insert id

    $this->conn->lastInsertId();

NOTE :: $this->conn : your PDO db connection

for number of rowcounts :

    return $this->insqry->rowCount();

NOTe :: $this->insqry : use for preparing query

Hytool
  • 1,358
  • 1
  • 7
  • 22