php fetchassoc 跨表,php-mysqli_fetch_assoc-如果同时更改数据会怎样?
在PHP中,我在while循環(huán)中使用mysqli_fetch_assoc()來(lái)獲取特定查詢中的所有記錄.
我想知道如果在運(yùn)行循環(huán)時(shí)(通過(guò)另一個(gè)進(jìn)程或服務(wù)器)更改了數(shù)據(jù),從而使記錄不再與查詢匹配,會(huì)發(fā)生什么情況.還會(huì)取嗎?
換句話說(shuō),當(dāng)您執(zhí)行query()時(shí),獲取的記錄數(shù)組是否固定?還是不是?
更新:
我了解這是一項(xiàng)功能,即在更改數(shù)據(jù)時(shí)結(jié)果集不會(huì)更改,但是如果您確實(shí)想這樣做,該怎么辦?在我的循環(huán)中,我對(duì)其他服務(wù)器已更新的記錄不感興趣.我該如何檢查,而不必對(duì)獲取的每個(gè)記錄進(jìn)行新查詢?
更新:
詳細(xì)說(shuō)明:
我正在研究某種搜索引擎抓取工具,用于在數(shù)據(jù)庫(kù)中搜索值.這是由幾個(gè)服務(wù)器同時(shí)完成的.報(bào)廢的物品將不再被搜索.我真的無(wú)法控制哪個(gè)服務(wù)器搜索哪個(gè)項(xiàng)目,我希望可以在獲取記錄集的同時(shí)檢查項(xiàng)目的狀態(tài).由于這是一個(gè)很大的數(shù)據(jù)集,因此我不會(huì)在搜索之前轉(zhuǎn)移整個(gè)結(jié)果集,而是在需要時(shí)提取每條記錄…
解決方法:
介紹
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容易受到表更新和查詢結(jié)果集迭代之間的競(jìng)爭(zhēng)條件的影響,那將是不值得的.
當(dāng)然,就數(shù)據(jù)庫(kù)本身而言,在更改任何數(shù)據(jù)之前,您的SELECT查詢已經(jīng)完成.結(jié)果集將緩存在數(shù)據(jù)庫(kù)和PHP腳本之間的層中的某個(gè)位置.
深入的
In the context of databases, a single logical operation on the data is called a transaction.
用戶啟動(dòng)的事務(wù)可以包含多個(gè)連續(xù)查詢,但是ISO / IEC 9075-2中的4.33.4和4.33.5描述了如何在每個(gè)查詢級(jí)別隱式進(jìn)行查詢:
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??
你不可以.
盡管可以控制連接器執(zhí)行的緩沖類型(在本例中為MySQLi),但不能覆蓋上述SQL的低級(jí)事實(shí):INSERT或UPDATE或DELETE都不會(huì)影響正在進(jìn)行的SELECT.
SELECT完成后,結(jié)果是獨(dú)立的.您可以控制此獨(dú)立數(shù)據(jù)的傳輸緩沖,但這并不能真正幫助您完成聽(tīng)起來(lái)像您想做的事情.
坦率地說(shuō),這很幸運(yùn),因?yàn)槟胱龅氖虑槁?tīng)起來(lái)很奇怪!
標(biāo)簽:mysqli,php
來(lái)源: https://codeday.me/bug/20191208/2088560.html
總結(jié)
以上是生活随笔為你收集整理的php fetchassoc 跨表,php-mysqli_fetch_assoc-如果同时更改数据会怎样?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: win7冒险岛java,win7玩冒险岛
- 下一篇: oracle var/tmp,关于/va