简体   繁体   English

PHP不同的查询结果-MySQL Workbench与PHP执行

[英]PHP Different Query Results - MySQL Workbench vs PHP Execution

I'm running the following query using MySQL workbench and I'm getting the exact results from the database : 我正在使用MySQL工作台运行以下查询,并且从数据库中获取了准确的结果:

SELECT * 
FROM ODB_RG 
WHERE fullAddressV1 = 'רמת גן חרושת 1' 
    OR fullAddressV2 = 'רמת גן חרושת 1' 
    OR fullAddressV3 = 'רמת גן חרושת 1' 
    OR fullAddressV4 = 'רמת גן חרושת 1'

On the other hand, running the following php code does, that actually generated an equivalent query to the one mentioned above,does not return any record : 另一方面,运行以下php代码确实会产生与上述查询等效的查询,但不会返回任何记录:

$fullAddress = "1 רמת גן חרושת";
$stmt = $con->prepare("SELECT * FROM ODB_RG WHERE fullAddressV1 = :address1 "
        . "OR fullAddressV2 = :address2 OR fullAddressV3 = :address3 "
        . "OR fullAddressV4 = :address4");

$stmt->bindParam(':address1',$fullAddress);
$stmt->bindParam(':address2',$fullAddress);
$stmt->bindParam(':address3',$fullAddress);
$stmt->bindParam(':address4',$fullAddress);

$status = $stmt->execute();

The only reasonable cause that might lead to the difference between the solution is the Hebrew string that is passed as a parameter. 可能导致解决方案差异的唯一合理原因是希伯来语字符串作为参数传递。

Any of you have any idea what should be done in order to fix it ? 你们中的任何人都知道如何解决该问题? Thanks in advance ! 提前致谢 !

EDIT : This is the collation i'm using for the relevant table: 编辑:这是我用于相关表的排序规则:

engine=MyISAM charset=UTF8 COLLATE = utf8_general_ci;

This is what I meant by error checking: 这就是我所说的错误检查的意思:

$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$fullAddress = "1 רמת גן חרושת";
$stmt = $con->prepare("SELECT * FROM ODB_RG WHERE fullAddressV1 = :address1 "
        . "OR fullAddressV2 = :address2 OR fullAddressV3 = :address3 "
        . "OR fullAddressV4 = :address4");

if (!$stmt) {
    echo "\nPDO::errorInfo():\n";
    print_r($con->errorInfo());
    die();
}

$stmt->bindParam(':address1',$fullAddress);
$stmt->bindParam(':address2',$fullAddress);
$stmt->bindParam(':address3',$fullAddress);
$stmt->bindParam(':address4',$fullAddress);

$status = $stmt->execute();

if (!$status ) {
    echo "\nPDO::errorInfo():\n";
    print_r($con->errorInfo());
    die();
}
if($row = $stmt->fetch()){
   var_dump($row);
}else{
   echo 'no row found';
}

I know its ulgy, sometime called defensive programming, but it lets you know whats going on. 我知道它很麻烦,有时称为防御性编程,但它可以让您知道发生了什么。

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

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