Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP MYSQL问题读取最近更新的行_Php_Mysql_Cakephp_Cron - Fatal编程技术网

CakePHP MYSQL问题读取最近更新的行

CakePHP MYSQL问题读取最近更新的行,php,mysql,cakephp,cron,Php,Mysql,Cakephp,Cron,伙计们,我正在使用CakePHP,在获取我在DB中设置的最近更新的标志时遇到了一个问题 这是密码 $this->loadModel('Setting'); $s=$this->Setting->find('first'); if($s['Setting']['inprogress']==1) { echo "still working..."; exit; } $s['Setting']['inprogress']=1; $this->

伙计们,我正在使用CakePHP,在获取我在DB中设置的最近更新的标志时遇到了一个问题

这是密码

$this->loadModel('Setting');
$s=$this->Setting->find('first');
if($s['Setting']['inprogress']==1)
 {
        echo "still working...";
        exit;
 }

$s['Setting']['inprogress']=1;
$this->Setting->Save($s);

//// Some code that is using db table and process data for like 30-40 seconds

$s['Setting']['inprogress']=0;
$this->Setting->Save($s);
exit;
此代码由cron作业运行,检查的目的是确保下一个cron作业在第一个cron作业完成之前不会接触数据。但显然,cron作业是并行运行的,因为它们根本没有得到inprogress=1

但是,如果我使用PHPMyAdmin手动检查记录,inprogress标志立即变为1,但不知何故,它将无法用于下一个http调用


有什么想法吗

为什么不直接使用保存字段

因此,与其

$s['Setting']['inprogress']=1;
$this->Setting->Save($s);
你可以

$this->Setting->saveField('inprogress', 1);
或者更好,可以肯定的是,如果在您保存的设置模型之间进行了其他查找,您可以这样做

$id = $s['Setting']['id'];
$this->Setting->id = $id;
$this->Setting->saveField('inprogress', 1);

很抱歉,这可能是一个代码优化建议,但不是我问题的解决方案。谢谢