PHP+MYSQL_locks .....请帮忙.....我被困在这个..?

标签 php mysql

我在 php 中创建了一个文件,并在该文件下编写了一段代码来锁定具有读取模式的表。 在那个文件下面,我在同一个表中写了一个插入操作,但是我们知道读锁只支持读操作,这意味着你只能查看表中的内容,但不能修改它。它运行良好。

PROBLEM_EXIST_HERE:我创建了另一个文件,其中包含对同一个表的相同插入操作。这里只写插入操作,不写加锁代码。

在使用此文件之前,我使用 (RUN) 第一个文件(包含锁定+插入)操作,然后我在同一浏览器中打开新选项卡并运行第二个文件(仅包含插入操作)。

既然已经知道读锁已经固定在表上了,那么为什么还要进行插入操作呢?为什么它不向我显示一个错误,指出该表处于 READ 锁定模式,因此无法更新?有人知道如何解决这个问题吗?

  1. 有没有人知道如何知道在 mysql 数据库中一个表是否被锁定在读或写状态?任何人都可以告诉我这个的 php 代码吗?我搜索了一整天,但没有找到解决方案。请用简单的语言编写简单的解决方案。

最佳答案

查看 LOCK TABLE 的文档:

WRITE locks normally have higher priority than READ locks to ensure that updates 
are processed as soon as possible. This means that if one session obtains a READ 
lock and then another session requests a WRITE lock, subsequent READ lock requests 
wait until the session that requested the WRITE lock has obtained the lock and 
released it.

对于 InnoDB 表,InnoDB 有一个 Lock Monitor :

The InnoDB Lock Monitor is like the standard Monitor but also provides extensive lock
information. To enable this Monitor for periodic output, create a table named 
innodb_lock_monitor. 

更多:

The Lock Monitor is the same as the standard Monitor except that it includes additional 
lock information. Enabling either monitor for periodic output by creating the associated
InnoDB table turns on the same output stream, but the stream includes the extra 
information if the Lock Monitor is enabled. For example, if you create the innodb_monitor 
and innodb_lock_monitor tables, that turns on a single output stream. The stream includes 
extra lock information until you disable the Lock Monitor by removing the 
innodb_lock_monitor table. 

关于PHP+MYSQL_locks .....请帮忙.....我被困在这个..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12839487/

相关文章:

php - 这应该很容易,但我无法弄清楚

php - 使用 ODBC 使用 msaccess 创建 PHP PDO 连接时出现 fatal error

php - 如何在sphinx中使用子查询?

MySql表没有主键,django orm无法使用

PHP:如何以给定格式转换这句话

php - Wordpress:访问存储在主题文件夹中的子文件夹中的模板

PHP:我无法使用脚本连接或将表单数据发送到 mySQL

sql - mysql 中的多重连接

php - 一行与多列 mySQL 表中所有行的点积

mysql - 如何从 MySQL 存储过程始终返回空结果集?