Suppose that I have
“products” table with prod_id Auto_increment,
| prod_id | name |
and…
“images” table with id_image in Auto_Increment
id_image | filename | id_prod |
What i’m suppose to do for automatically store the “prod_id” value related to the new product JUST inserted, into the “id_prod” column images table without to recour to native functions like mysqli_insert_id($conn) or separate query, but just with a foreign key constraint instead ?
Is that Possible ?
Example:
Query nr.1 => INSERT INTO products (name) VALUES (productOne);
Query nr.2 => INSERT INTO images (name) VALUES (immagine.jpg)
I’d like the “images.id_prod” column could automatically be populated because of following “products.prod_id”.