Home > Archive > MySQL Server Forum > June 2005 > Any Ideas about that ...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Any Ideas about that ...
Angelos

2005-06-16, 3:23 am

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


Aggro

2005-06-16, 11:23 am

Angelos wrote:

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


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.

C:
http://dev.mysql.com/doc/mysql/en/g...-unique-id.html

PHP:
http://fi2.php.net/manual/fi/functi...l-insert-id.php

ODBC:
http://dev.mysql.com/doc/mysql/en/o...-insert-id.html
Angelos

2005-06-16, 11:23 am

> 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.


> PHP:
> http://fi2.php.net/manual/fi/functi...l-insert-id.php


THanks a lot man ....

Thats great news !!!!


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com