Is MySQL "thread safe" from a php script? Is MySQL "thread safe" from a php script? php php

Is MySQL "thread safe" from a php script?


MySQL uses locking (table-level for MyISAM or row-level for InnoDB), which does not allow 2 processes (2 calls to the script) to modify the same row. So the table won't crash*, but it's possible that MySQL can't handle the number of request in reasanoble time and the requests will wait. You should always optimize your queries to be as fast as possible.

*MyISAM could crash on insert/update intensive applications, but it has automatic recovery. However keep in mind that in such application, InnoDB has far better performance


is it always "safe" (ie, will not result in corrupt tables or collisions during requests)?

yes

If so, how does php/mysql achieve this?

table/row locks.


MySQL uses locks for Isoloation, and transactions for Atomicity. Transactions require InnoDB or BDB. InnoDB supports full ACID support.

Locks and transactions, combined, will resolve your concurrency issue.

By default, MySQL has implicit transactions.

Definitely learn about these features to see if they fit the bill. MyISAM uses table locking, whereas InnoDB provides row level locking, so one may serve your needs better than the other.