Let’s suppose API server access the SQL server from request, the connection for the MySQL server is such.
@mysql_connect(HOSTNAME,DATABASE_USER, DATABASE_PASSWORD) or die('Could not connect to : ' . mysql_error());
@mysql_select_db(DATABASE_NAME) or die( "<-----------------------Unable to select database------------------>");
is there a way to detect whether the connection is already opened? If it’s opened then make a sql transaction.
Let’s say while accessing table A, another API request call from outside come in and wanting to acess table B.
IS it possible to initiate an access to table B while table A operation still in progress.
In other word, don’t wait access Table A to finish. As soon as access Table B come in then start it.
@jasonwhite I believe that concurrency is handled at the DBMS level, which, depending on the operation in question, already supports the possibility of two operations running at the same time. If for example, operation one were a SELECT operation, and operation two were an INSERT operation both could be executed at the same time. In fact, regardless of the operation types this would be possible, except if the tables were related via a foreign key constraint. This is because MySQL implements table-locking during operations, in which it locks a table while an operation is being executed on it, and then releases the table once that operation is completed.
Regarding checking if a connection already exists, you would need to implement a singleton method that would check if the connection already exists. If it does not, create it and return it; if it does, return the existing connection. This would look something like this:
AFAIK, you have no further control over whether one operation will wait for another during execution. My $0.02.