简体   繁体   English

PDO在页面加载时更新数据库

[英]PDO Updating Database on Page load

I am building a cms using php,pdo in oop format. 我正在使用oop格式的php,pdo构建cms。 On various pages i call functions to update the database on page load in order to keep the database up to date in real time ( Entire site is User content driven things need to be updated and fixed in database outside of forms so i update database on page load for certain things ). 在不同的页面上,我调用函数以在页面加载时更新数据库,以使数据库实时更新(整个站点是用户内容驱动的,需要在表单外的数据库中进行更新和修复,因此我在页面上更新数据库加载某些内容)。

Example

$expiredMatches = $db->fetchAll("SELECT * FROM matches WHERE match_date <= $now AND status = 0");

so the above fetches all matches that need to have their status set to 2 ( expired ) I then loop through each and process point refunds if they are necessary 因此,上面获取了所有需要将其状态设置为2(过期)的匹配项,然后逐个循环,并在必要时处理点数退款

foreach ($expiredMatches as $em) {
    // Check to see if points were used
         // If ^ Yes then refund users 
}

This may be a dumb question but i have not thought about it much until now. 这可能是一个愚蠢的问题,但到目前为止我还没有考虑太多。 My question is this. 我的问题是这个。

If the page is loaded by multiple users at the same time will the refunded users receive multiple refunds? 如果页面同时由多个用户加载,则退款用户会收到多次退款吗?

Link to PDO transactions manual: http://www.php.net/manual/en/pdo.transactions.php 链接到PDO交易手册: http : //www.php.net/manual/zh/pdo.transactions.php

"any work carried out in a transaction, even if it is carried out in stages, is guaranteed to be applied to the database safely, and without interference from other connections, when it is committed." “在事务中进行的任何工作,即使它是分阶段进行的,都可以保证在提交时安全地应用于数据库,并且不受其他连接的干扰。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM