php fetchassoc 跨表,php-mysqli_fetch_assoc-如果同时更改数据会怎样?

在PHP中使用mysqli_fetch_assoc()遍历查询结果时,即使数据在循环过程中被其他进程更新,结果集仍保持不变。这是因为数据库事务的隔离性确保了查询的稳定性。然而,如果希望忽略已更新的记录,你需要在每次检查时执行新的查询或使用其他同步机制来判断记录状态。这种做法可能会增加系统的复杂性和开销。
摘要由CSDN通过智能技术生成

在PHP中,我在while循环中使用mysqli_fetch_assoc()来获取特定查询中的所有记录.

我想知道如果在运行循环时(通过另一个进程或服务器)更改了数据,从而使记录不再与查询匹配,会发生什么情况.还会取吗?

换句话说,当您执行query()时,获取的记录数组是否固定?还是不是?

更新:

我了解这是一项功能,即在更改数据时结果集不会更改,但是如果您确实想这样做,该怎么办?在我的循环中,我对其他服务器已更新的记录不感兴趣.我该如何检查,而不必对获取的每个记录进行新查询?

更新:

详细说明:

我正在研究某种搜索引擎抓取工具,用于在数据库中搜索值.这是由几个服务器同时完成的.报废的物品将不再被搜索.我真的无法控制哪个服务器搜索哪个项目,我希望可以在获取记录集的同时检查项目的状态.由于这是一个很大的数据集,因此我不会在搜索之前转移整个结果集,而是在需要时提取每条记录…

解决方法:

介绍

I’m wondering what happens if the data is changed while running the loop (by another process or server), so that the record doesn’t match the query any more. Will it still be fetched?

是.

In other words, is the array of records that are fetched fixed, when you do query()? Or is it not?

是.

如果DBMS容易受到表更新和查询结果集迭代之间的竞争条件的影响,那将是不值得的.

当然,就数据库本身而言,在更改任何数据之前,您的SELECT查询已经完成.结果集将缓存在数据库和PHP脚本之间的层中的某个位置.

深入的

In the context of databases, a single logical operation on the data is called a transaction.

用户启动的事务可以包含多个连续查询,但是ISO / IEC 9075-2中的4.33.4和4.33.5描述了如何在每个查询级别隐式进行查询:

The following SQL-statements are transaction-initiating

SQL-statements, i.e., if there is no current SQLtransaction, and an

SQL-statement of this class is executed, then an SQL-transaction is

initiated, usually before execution of that SQL-statement proceeds:

All SQL-schema statements

The following SQL-transaction statements:

.

.

.

.

The following SQL-data statements:

[..]

.

.

.

[..]

[..]

另外,4.35.6:

Effects of SQL-statements in an SQL-transaction

The execution of an SQL-statement within an SQL-transaction has no

effect on SQL-data or schemas [..]. Together with serializable

execution, this implies that all read operations are repeatable

within an SQL-transaction at isolation level SERIALIZABLE, except

for:

1) The effects of changes to SQL-data or schemas and its contents

made explicitly by the SQL-transaction itself.

2) The effects of differences in SQL parameter values supplied to externally-invoked

procedures.

3) The effects of references to time-varying system

variables such as CURRENT_DATE and CURRENT_USER.

您的广泛要求

I understand that it’s a feature that the resultset is not changed when the data is changed, but what if you actually WANT that? In my loop I’m not interested in records that are already updated by another server. How do I check for that, without doing a new query for each record that I fetch??

你不可以.

尽管可以控制连接器执行的缓冲类型(在本例中为MySQLi),但不能覆盖上述SQL的低级事实:INSERT或UPDATE或DELETE都不会影响正在进行的SELECT.

SELECT完成后,结果是独立的.您可以控制此独立数据的传输缓冲,但这并不能真正帮助您完成听起来像您想做的事情.

坦率地说,这很幸运,因为您想做的事情听起来很奇怪!

标签:mysqli,php

来源: https://codeday.me/bug/20191208/2088560.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值