简体   繁体   English

MySQLi在where子句中使用date(now())加入

[英]MySQLi join using date(now()) in where clause

I am running this query in phpmyadmin and it works fine. 我在phpmyadmin中运行此查询,它工作正常。 But on running it in joshcam's MySQLi Database class it gets wrong data 但是在joshcam's MySQLi Database类中运行它会得到错误的数据
Query: 查询:

SELECT 
    s.az
    , s.ta
    , s.zamanSarfShode
    , p.name
FROM 
    saateruzane s 
JOIN 
    projhe p 
JOIN 
    kareruzane k
WHERE 
    s.ProjheId = p.id
AND 
    k.id = s.ruzId 
AND 
    k.ruzGregorian = date(now())   

PHP code : PHP代码:

$con->join('projhe p', 's.ProjheId = p.id');
$con->join('kareruzane k', 'k.id = s.ruzId');
$con->joinWhere('kareruzane k','k.ruzGregorian', 'date(now())');
$tines = $con->get('saateruzane s',null,'s.az ,s.ta ,s.zamanSarfShode ,p.name');

The definition for joinWhere is joinWhere的定义是

public function joinWhere($whereJoin, $whereProp, $whereValue = 'DBNULL', $operator = '=', $cond = 'AND')

So you don't need to pass in every part. 因此,您不需要传递所有内容。 Instead, try this: 相反,请尝试以下操作:

$con->joinWhere('kareruzane k','k.ruzGregorian = date(now())');

Though better than date(now()) is CURDATE() 虽然比date(now())好于CURDATE()

$con->joinWhere('kareruzane k','k.ruzGregorian = curdate()');

However, I'm not sure you should be using a join here, since it's part of the WHERE clause on your original query, not the JOIN clause. 但是,我不确定您是否应该在此处使用JOIN ,因为它是原始查询的WHERE子句的一部分,而不是JOIN子句的一部分。 So instead do 所以做

$con->where('k.ruzGregorian = curdate()');

With just a fast look on this lib docs, I found this: 通过快速查看此lib文档,我发现了这一点:

'createdAt' => $db->now(),
// createdAt = NOW()

https://github.com/joshcam/PHP-MySQLi-Database-Class#insert-query https://github.com/joshcam/PHP-MySQLi-Database-Class#insert-query

In your case try use 在你的情况下尝试使用

$con->joinWhere('kareruzane k','k.ruzGregorian', $con->now());

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

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