0

I'm running the following query using MySQL workbench and I'm getting the exact results from the database :

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 :

$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;
Itamar
  • 45
  • 10

1 Answers1

1

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.

meda
  • 45,103
  • 14
  • 92
  • 122