如果mysql命令给出结果,PHP会出错


PHP err if mysql command gives a result

我有这个查询

 $DB->query("SELECT id FROM tfilter WHERE '". $Properties['Title'] ."' LIKE CONCAT('%', filter, '%')");

我需要它这样做,这样如果得到结果,scrip就会死,现在我有这个:

    if($DB->record_count() != 0) {
    $Err = '<b>This cant be uploaded</b>';
    include(SERVER_ROOT . '/sections/upload/upload.php');
    die();
if($DB->record_count() != 0) {

这应该是els吗?因为它没有死,尽管我知道它得到了的结果

这个查询在php脚本中看起来像这样。它是更大站点的一部分

$DB->query("SELECT id FROM tfilter WHERE '". $Properties['Title'] ."' LIKE CONCAT('%', filter, '%')");
 if($DB->record_count() != 0) {
 $Err = '<b>This cant be uploaded</b>';
 include(SERVER_ROOT . '/sections/upload/upload.php');
 die();
 $Properties['Title'] = String from the upload script that contains the titel.
 $DB is the call til mysql
 filter = the row in mysql
 tfilter = the database name

我需要什么:

我需要php在FILTER行的选项卡TFILTER中搜索与$Properties['Title']的匹配项,如果找到任何匹配项,则DIE。如果FILTER行中存在字符串the.White.Tiger.,并且$Properties['Title']包含the.White.Tiger.in.the.Yard,则php应该会消亡。

我认为您的查询需要是(用backtick重新排列$Properties['Title']周围的单引号):

$DB->query("SELECT id FROM filter WHERE `". $Properties['Title'] ."` LIKE CONCAT('%', filter, '%')");

此外,您不需要使用concat函数来前置和附加%字符,只需按如下方式使用即可:

$DB->query("SELECT id FROM filter WHERE `". $Properties['Title'] ."` LIKE '%{$filter}%'");

您不能使用rowCount()?

所以它应该看起来像这样:

$stmt = $DB->query("SELECT id FROM tfilter WHERE '". $Properties['Title'] ."' LIKE CONCAT('%', filter, '%')");
$numrows=$stmt->rowCount();
$error= $stmt->errorInfo();
echo $error[2];
if($numrows) {
$Err = '<b>This cant be uploaded</b>';
include(SERVER_ROOT . '/sections/upload/upload.php');
die();