为什么PC和笔记本电脑的代码结果不同

时间:2019-12-02 16:52:51

标签: php mysql date datetime xampp

ich在这里先说一下我的威胁 PHP MySQL How to select 2 specific and 1 common value over 2 tables? 并使我感到困惑,但首先是重要代码部分:

$stmt = $pdo->prepare("SELECT
  table1.spediteur,
  table2.versendet,
  table2.unique_code,
  table1.unique_code
FROM table1
  INNER JOIN table2
    ON table1.unique_code = table2.unique_code
WHERE table1.unique_code = $scanned_number
AND table2.unique_code = $scanned_number
GROUP BY table1.spediteur,
         table2.versendet,
         table2.unique_code,
         table1.unique_code
HAVING table1.spediteur = 'Dachser'
AND table2.versendet = '0000-00-00 00:00:00'
");

$stmt->execute([$scanned_number]);
$result = $stmt->fetch();
if ($result) { 
?> the scanned number matches the given parameter 

<?php 
$sql = "UPDATE table2 SET versendet = date('Y-m-d H:i:s') WHERE unique_code = $scanned_number";
    $stmt = $pdo->prepare($sql);
    $stmt->execute();

} else { 
?> the scanned number don´t matches 
<?php
}?>

此函数只是查找一些相似的值和现有值。 它可以通过Xampp PHP版本7.3.7在我的PC上运行/ Xampp上的Laptopversion是7.1.11

在我的PC上,服务器字符集是cp1252西欧(latin1) 在我的笔记本电脑上,它也是cp1252西欧(latin1)。 utf8mb4具有相同的结果。 好的,现在是最后一个序列: AND table2.versendet = '0000-00-00 00:00:00' 看,那边有没有。

在我的PC上,这对于我的代码就足够了,如果 保存的值为'0000-00-00 00:00:00'->代码将使用当前日期时间对其进行更新。

如果我在笔记本电脑上启动此代码,则代码说,“ 0000-00-00 00:00:00”不存在,并给我一条错误消息。 但是如果我将代码更改为 AND table2.versendet = date('Y-m-d' H:i:s' = '0000-00-00 00:00:00') 它就像在我的PC上一样工作,我绝对不知道为什么。

因此,如果有人了解我,请告诉:谁是我的错误。在此先感谢:)

1 个答案:

答案 0 :(得分:1)

这是一个有效查询的示例。虽然它可能无法解决您的所有问题,但至少是一个更好的起点...

SELECT DISTINCT t1.unique_code -- pointless to select both columns when we know (because we have specified) that both hold the same value
              , t1.spediteur   -- obviously we know that this will be 'Dachser'
              , t2.versendet   -- and this will be '0000-00-00 00:00:00'
                               -- (assuming correspondong rows exist)
           FROM table1 t1
           JOIN table2 t2
             ON t2.unique_code = t1.unique_code
          WHERE t1.unique_code = ?
            AND t1.spediteur = 'Dachser'
            AND t2.versendet = '0000-00-00 00:00:00'