I have a database on XAMPP and I use php in order to manipulate the database. I wish to read and write the database in concurrency way and each table are connected with the others. I don't understand if my approach is right.
When I wish to read I use this mode:
$connection = new mysqli($host, $user, $password, $dbName);
if (connection->connect_errno)
return false;
$connection->autocommit(true);
$result = mysqli_query($connection, $query);
if (!$result)
return false;
else
return true;
$connection->close();
And when I wish to write I use $connection->autocommit(false);
with commit or rollback at the end.
But I wish to know if some users is reading and in this moment one or more people write on the database, does the database remain in right? And there is a way to put in an queue the write/read in order don't stop the user but putting in an spin wait?
I have also read that mysqli has mysqli_begin_transaction
so I have thought that it is possibile to use mysqli_begin_transaction
when I have to write, but I'm not sure that it is right.
Have you some ideas in order to read and write on the database in concurrency way without to stop any transaction but put in an spin wait queue?
I have thought a way like mutex like the c with some lock (I wish to implement at the end this):
I wish to write:
- I wait the lock in order to write and to block the other user;
- I lock the database and the others remains on spin wait;
- Here to check using php if the new records are right doing new query into the database but the database is locked only for user not for checking.
- Write database;
- unlock database.
When I wish to read:
- I wait if somebody finish to write;
- I read;