Shane Wegner wrote:
> I wrote an application which uses threads and I am planning to add Mysql
> support. My question is one relating to design and that is when a
> multithreaded program uses Mysql using the mysqlclient library, is it best
> to have each thread connect to the Mysql server seperately or is it safe
> to use a shared handle. The MYSQL_RES and MYSQL_ROW would be local to the
> thread of corse but can the handle be global? If it can, what will happen
> when two threads submit a query? Will the second wait until the first
> completes or should this construct just be avoided?
> Shane Wegner: shane@stripped
You have to give each thread its own connection.
Mysql connections can't handle two concurrent queries.
If you want to reduce the amount of open connections, you can create a connection pool.
This obviously only will spare some connections as long as not all threads are querying at
the same time.