Any Ideas about that ...

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello ...

I have a table Products and a table Files.
Each product may have from 0 to 10 or more files associated with it. So it
is a 1 to M relationship...
My problem is that I cannont see how I can associate files to the product at
the time of Product insertion to the DB.

And this is because I don't know the ID taht the product is going to take
before it is inserted into the DB.

So any IDEAS ?
Thanks Angelos

Re: Any Ideas about that ...

Angelos wrote:

Quoted text here. Click to load it

First insert the product, then get the id for it using last_insert_id()
and then insert rest of the rows, using that id. (C, PHP and other
implementations have direct function for that, with ODBC you need to run
new query to get it).

And the id last_insert_id() returns is safe to use even with many users,
because it is attached to the current connection. So user with another
connection wont get the id you used in another connection.




Re: Any Ideas about that ...

Quoted text here. Click to load it

THanks a lot man ....

Thats great news !!!!

Site Timeline