Note. I used google translator to write this
I always did the following for working with MySQL:
-> Open Connection to the database.
-> see details
-> Insert Data
-> another query
-> close Connection
I usually use the same connection to do different things before closing. A friend who studies this on Mexico's IPN told me that the right way (for security) is to create a new connection for each request, for example:
-> Open Connection to the database.
-> see details
-> close Connection
-> Open Connection to the database.
-> Insert Data
-> close Connection
-> Open Connection to the database.
-> another query
-> close Connection
My question is: what to do right? My method was to make the minimum number of database queries and only establish a connection and keep it until it no longer serves me.
Also, is it possible to do double insertion into a table? For instance:
insert into table1(relacion) values([insert into tablaRelacionada(id) values("dato")]);
and that "relacion" is the inserted identifier from the first request in "tablaRelacionada".