为什么这个mysql查询返回空结果

时间:2012-09-03 11:03:52

标签: php mysql character-encoding parameters

此功能旨在从两个单独的医生和诊所中返回医生的信息

function searchSubs($spc, $stt, $name, $ls, $ll){
    $query ='
        SELECT doctor.*, clinic.address
        FROM doctor
        LEFT JOIN clinic
            ON ( doctor.id = clinic.dr <<STATE CONDITION>>)
        WHERE doctor.dr_name REGEXP  :dr <<SPECIALIZATION CONDITION>>
            AND doctor.active = 1
        LIMIT :s, :l;
        '
    ;

    $query = ($spc == 0) ? str_replace('<<SPECIALIZATION CONDITION>>','',$query): str_replace('<<SPECIALIZATION CONDITION>>',' AND `doctor`.`specialization` = :sp ',$query);
    $query = ($stt == 0) ? str_replace('<<STATE CONDITION>>','',$query): str_replace('<<STATE CONDITION>>',' AND `clinic`.`governorate` = :st ',$query);

    $searchPDO = new PDO(DNS,ReaderUser,ReaderPass);
    $searchPDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
    $searchPDO->exec("SET CHARACTER SET utf8");

    $stmt = $searchPDO->prepare($query);

    if ($spc != 0) $stmt->bindParam(":sp",$spc,PDO::PARAM_INT);
    if ($stt != 0) $stmt->bindParam(":st",$stt,PDO::PARAM_INT);
    $stmt->bindValue(":dr",'.*'.$name.'.*',PDO::PARAM_STR);
    $stmt->bindParam(":s",$ls,PDO::PARAM_INT);
    $stmt->bindParam(":l",$ll,PDO::PARAM_INT);

    $stmt->execute();

    $Drs = $stmt->fetchAll(PDO::FETCH_ASSOC);
    return $Drs;
}

当我调用这样的函数时,它工作正常:

$drs = searchSubs('12', 6, '<<some Arabic name here>>' , 0, 10);

当我这样称呼它时它不会出现:

$SDrs = searchSubs($specialization,$state,$name,$s,$l);

我花了最后2天寻找原因,但没有, 我已经url_decoded字符串变量$name尝试了数据库中的数据类型的许多不同方式,但没有,

0 个答案:

没有答案