Php MySQL更新查询不工作
我有一个MySQL表,它有以下列Php MySQL更新查询不工作,php,mysql,sql-update,unix-timestamp,Php,Mysql,Sql Update,Unix Timestamp,我有一个MySQL表,它有以下列 urlByCustomer table ---------------------------------------------- |customerID | TeamID | date | numUrlsConsumed| ---------------------------------------------- | | | | | ------------------------
urlByCustomer table
----------------------------------------------
|customerID | TeamID | date | numUrlsConsumed|
----------------------------------------------
| | | | |
----------------------------------------------
urlmapping
Column Type Null Default Comments MIME
urlMappingID bigint(20) No
customerID int(11) Yes 0
activityID int(11) Yes 0
contactID int(11) Yes 0
fullURL mediumtext Yes NULL
lastModified timestamp No CURRENT_TIMESTAMP
developerSandbox varchar(25) Yes
我有一个正在执行的代码来更新表
$start = strtotime(date('Y-m-d 00:00:00'));
$end = strtotime(date('Y-m-d 23:59:59'));
$countAllThisGuysVals = "SELECT COUNT( DISTINCT`customerID`,`fullURL`)
FROM `urlmapping`
WHERE `urlMappingID` >= $ORIGINAL_COPY
AND `customerID` = $currentCustomerID";
$countTheVals= $conn->query($countAllThisGuysVals);
$countedfinal =0;
foreach ($countTheVals as $countRow) {
$countedfinal = array_sum($countRow)/2;
}
$tableUpdateQuery = "UPDATE `urlByCustomer`
SET `date` = NOW()
WHERE `customerID`= $currentCustomerID AND
UNIX_TIMESTAMP(`date`) BETWEEN '{$start}' and '{$end}'";
$conn->exec($tableUpdateQuery);
$tableUpdateQuery = "UPDATE `urlByCustomer`
SET `numUrlsConsumed` = $countedfinal
WHERE `customerID`= $currentCustomerID AND
UNIX_TIMESTAMP(`date`) BETWEEN '{$start}' and '{$end}'";
$conn->exec($tableUpdateQuery);
echo "update path <br>";
$tableModified = true;
$originalLPID++;
$start=strottime(日期('Y-m-d 00:00:00');
$end=strottime(日期('Y-m-D23:59:59');
$COUNTALLTHISGYSVALS=“选择计数(不同的'customerID','fullURL'))
来自“urlmapping”
其中`urlMappingID`>=$ORIGINAL\u COPY
和“customerID`=$currentCustomerID”;
$countTheVals=$conn->query($countallthisgueysvals);
$countedfinal=0;
foreach($countTheVals为$countRow){
$countedfinal=array_sum($countRow)/2;
}
$tableUpdateQuery=“UPDATE`urlByCustomer`
设置`date`=NOW()
其中`customerID`=$currentCustomerID和
在{$start}和{$end}之间的UNIX_时间戳(`date`);
$conn->exec($tableUpdateQuery);
$tableUpdateQuery=“UPDATE`urlByCustomer`
设置'numUrlsConsumed`=$countedfinal
其中`customerID`=$currentCustomerID和
在{$start}和{$end}之间的UNIX_时间戳(`date`);
$conn->exec($tableUpdateQuery);
回显“更新路径
”;
$tableModified=true;
$originalLPID++;
变量几乎都是声明的,但是声明是分散的,所以我只是发布这部分来缩短它。对日期列的更新查询似乎正在运行,但第二次更新没有运行。但是它在17分钟前就工作了,所以我很困惑,因为在下一次测试之间唯一的变化是我添加了一些新值,这应该会导致它更新该列
Idk。我想有一种可能是UNIX\u时间戳。我在Mac上并行运行这个程序,所以我不确定时间戳转换为什么。看起来您在第一次更新中更改了“date”的值,而没有考虑到第二次更新现在在WHERE子句中找不到相同的行(因为您刚刚更改了日期) 您可以在一条语句中进行更新::
UPDATE urlByCustomer
SET `date` = NOW()
, numUrlsConsumed = $countedfinal
WHERE customerID= $currentCustomerID
AND UNIX_TIMESTAMP(`date`) BETWEEN '{$start}' and '{$end}'
因此,它不是在工作,而是在做什么?请给出
urlmapping
的结构,在代码中,您引用表urlByCustomer
,但在您的帖子中,您称之为customerByUrl
-这是同一个表吗?您是否回显了您的查询并直接在数据库中运行,比如在phpmyadmin或者类似的地方?检查错误?如何在运行时解析$ORIGiNAL_拷贝?