我的思想完全被这个所打动。完全相同的查询在使用mysqli_query()运行时返回零结果,但通过phpmyadmin预计会得到两个结果。我有双重和三重检查我正在运行相同的查询。相同的查询,相同的数据库,不同的结果
的PHP:
$sql = "SELECT assignment_id, next_deadline FROM " . TBL_ASSIGNMENTS . " WHERE (next_deadline >= $after_from AND next_deadline < $after_to) OR (next_deadline >= $before_from AND next_deadline < $before_to) AND stage = 1";
$result = $db->query($sql);
if (!$result)
{
trigger_error($db->error(), E_USER_ERROR);
}
die('Count: '.$db->numRows($result).'<br /><br />'.$sql);
的$ db对象是我已经使用了很长一段时间的MySQLi函数的简单包装,所以这个问题是不存在的。包装正在为其他地方的类似查询工作。
输出:
Count: 0
SELECT assignment_id, next_deadline FROM assignments WHERE (next_deadline >= 1400306400 AND next_deadline < 1400310000) OR (next_deadline >= 1400436000 AND next_deadline < 1400439600) AND stage = 1
我然后运行在phpMyAdmin此相同的SQL查询(CED + PED),并得到预期的2分的结果。
注意我也循环结果并手动计算而不使用mysqli_num_rows,结果相同。
任何想法可能是造成这个?我的心真的被烧断,毕竟,phpMyAdmin是通过PHP也运行它们...
PS,柜面你怀疑包装,这里有相关功能:
function __construct(){
$this->link = mysqli_connect($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
mysqli_set_charset($this->link, 'utf8');
$this->config = $this->createConfig();
// tell the server to run the close function on script shutdown
register_shutdown_function(array(&$this, 'close'));
}
function query($query){
$this->lastQuery = $query;
$this->querycount++;
$timestart = microtime(true);
$result = mysqli_query($this->link, $query);
$querytime = microtime(true) - $timestart;
$this->querytotal = $this->querytotal + $querytime;
$this->queryarray[$this->querycount] = array('query' => $query, 'time' => $querytime);
return $result;
}
function numRows($result){
return mysqli_num_rows($result);
}
提前许多感谢任何帮助你可以给..
克里斯
编辑: 现在也试过同样的SQL查询的变种都无济于事,包括加括号:
SELECT assignment_id, next_deadline FROM assignments WHERE ((next_deadline >= 1400306400 AND next_deadline < 1400310000) OR (next_deadline >= 1400436000 AND next_deadline < 1400439600)) AND stage = 1
我也尝试删除stage = 1结束,以隔离问题,并运行每个括号,但没有运气。例如
SELECT assignment_id, next_deadline FROM assignments WHERE next_deadline >= 1400306400 AND next_deadline < 1400310000
你运行SQL上都有相同的版本和变异? – BonzaiThePenguin
Web应用程序和phpmyadmin都与数据库(MySQL 5.5.37)位于同一台服务器上,并连接到本地主机。两者都使用php-fpm。为了让它变得更加令人难以置信,两者都使用mysqli –
我正在给出一个镜头,但是也许带有时间戳的'WHERE'过滤器在PHPMyadmin和mysqli中工作方式不同。我的意思是,PHPMyAdmin可以以某种方式操纵并显示正确的结果,mysqli没有这个功能。 –