简体   繁体   English

PHP代码中的Mysql查询不起作用

[英]The Mysql query in PHP code doesn't work

Here is the code where I want to select only "tbl_name,itime_end,itime_start" above a certain date in Timestamp: 这是我想在时间戳中的某个日期上方仅选择"tbl_name,itime_end,itime_start"的代码:

$reponse = $bdd->query('
SELECT 
tbl_name,
itime_end,
itime_start 
FROM table_ref 
WHERE `itime_start` > ".$Timestamp_UserStartDate." 
')

itime_start and $Timestamp_UserStartDate are in Timestamp itime_start$Timestamp_UserStartDate在时间戳中

but when I do a gettype, $timestamp_USerStartDate is an integer and $itime_start is a string. 但是当我执行gettype时, $timestamp_USerStartDate是一个整数,而$itime_start是一个字符串。 An echo $timestamp_USerStartDate; echo $timestamp_USerStartDate; gives : 1365408000 and an echo $donnees['itime_start']; 给出: 1365408000echo $donnees['itime_start']; gives : 1364998028 ... 给: 1364998028 ...

The result is that all the data selected are displayed without being filtered ! 结果是所有选择的数据都被显示而不被过滤! Thanks in advance for your advice ! 在此先感谢您的建议!

First off, you really shouldn't be injecting your variables the way that you're doing it. 首先,您实际上不应该按照您的方式注入变量。 You should bind variable placeholders and then populate them later. 您应该绑定变量占位符,然后在以后填充它们。 However, the issue with your code is that you're not ending your single parenthesis the way that you're intending to. 但是,代码的问题在于,您没有按预期的方式结束单个括号。 Try the line below 尝试以下行

$reponse = $bdd->query('SELECT tbl_name,itime_end,itime_start FROM table_ref WHERE `itime_start` > "'.$Timestamp_UserStartDate.'" ')

If you looked at the query as it is produced, you'd see it is not what you intended. 如果您查看查询的产生情况,就会发现它不是您想要的。

$reponse = $bdd->query("
    SELECT 
        tbl_name,
        itime_end,
        itime_start 
    FROM table_ref 
    WHERE `itime_start` > " . $Timestamp_UserStartDate
);

will do what you expect, provided that itime_start and $Timestamp_UserStartDate both are UNIX timestamps. 只要itime_start$Timestamp_UserStartDate都是UNIX时间戳,它将按照您的期望进行操作。

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

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