我正在构建一个在WordPress网站上运行的小型PHP脚本。COUNT查询在使用时返回null
我想查询我的表中有多少项目有特定的电子邮件。出于某种原因,它不起作用时,不使用where
语句,但一旦我添加WHERE [email protected]
,它将返回空值。我不知道为什么。
<?php
require('../wp-config.php');
$conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$email = $_GET['email'];
global $wpdb;
// This works
$countQuery = "SELECT COUNT(*) as count FROM `".$wpdb->prefix."mytable`";
// Once I add a filter, it returns null
$countQuery = $countQuery." WHERE `email`=`[email protected]`";
$rs = mysql_query($countQuery);
$result = mysql_fetch_array($rs);
// Later, I'd like to access $result['count']
// but the $result itself is NULL
var_dump("result", $result);
?>
我尝试添加以下行,看看我是否有任何错误,但没有额外的输出显示:
ini_set("display_errors", "1"); // shows all errors
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
error_reporting(E_ALL);
ini_set('display_errors', 'on');
如何解决这个问题?为什么这会出现?我不确定它是否与WordPress有任何关系,但由于仅仅通过添加WHERE [email protected]
就打破了功能。
你使用的邮件反引号是用于列名..所以mysql认为电子邮件地址是列名..尝试使用单引号..周围的电子邮件 – scaisEdge
我看到这被标记为重复。我其实并不认为对“重复”的引用将有助于OP。 *答案*几乎是相同的答案,但*问题*完全不同。 –