Jump to content

Insert product in db


ovy79ro

Recommended Posts

Hello,

 

I am working now at a script that insert products from an xml files. As i know, the id's from tables ps_product and ps_product_lang (and others) must correspond (foreign keys). My script will be like this:

 

foreach ............

 

$sql_1 = "INSERT ON `ps_product` (`id_supplier`, `id_manufacturer`, `id_tax_rules_group`,.........) VALUES ('abc', 'cde', '1',..........);

............................

$sql_2 = "INSERT ON `ps_product_lang` (`id_product`, `id_lang`, `description`,.........) VALUES ('???', '6', 'bla bla vla',..........);

........................................

 

On $sql_2, when insert on ps_product_lang, in column id_product i must insert same id_product from table ps_product. How can i do that? I know i must (or not) use sintax INSERT using SELECT from, but i don't know how to do that.

 

Thank you.

Edited by ovy79ro (see edit history)
Link to comment
Share on other sites

Thanks, but i don't see how this function can help me. Maybe LAST_INSERT_ID():

 

$value = "SELECT LAST_INSERT_ID() FROM `ps_product`";

$sql_2 = "INSERT ON `ps_product_lang` (`id_product`, `id_lang`, `description`,.........) VALUES ('$value', '6', 'bla bla vla',..........);

 

I will try this cod.

  • Like 1
Link to comment
Share on other sites

i try to use code:

$value = "SELECT LAST_INSERT_ID() FROM `ps_product`";

$sql_2 = "INSERT INTO `ps_product_lang` (`id_product`, `id_lang`, `description`,.........) VALUES ('$value', '6', 'bla bla vla',..........);

but it doesn't work. it work only if i set id_product auto_increment in ps_product_lang table. is something wrong if I set id_product auto_increment in ps_product_lang table?

Edited by ovy79ro (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...