DanCapitanDePlai
DanCapitanDePlai

Reputation: 457

Database query different results

I've encountered a new problem while editing my Magento store. This problem is PHP & MySQL related and not neccessary related to Magento because I tried using raw PHP code that dealt with the database, and not Magento handlers and helpers.

$a = "Tapet colectia Alice Whow C";

$sql = "
  SELECT *
  FROM `catalog_product_entity_varchar`
  WHERE `value` LIKE '%".$a."%'
  LIMIT 0, 30
";

When I search for the $a variable I'm getting 0 results, but when I search for the variable's value Tapet colectia Alice Whow C, I get the desired results.

Why is this happening?

Upvotes: 0

Views: 155

Answers (1)

nachito
nachito

Reputation: 7035

So you're making calls to a Magento database, huh? Well, here's how I usually do it:

require_once '/path/to/app/Mage.php';
Mage::app();

$db = Mage::getSingleton('core/resource')->getConnection('core_read');
$a = 'Tapet colectia Alice Whow C';
$select = $db->select()
             ->from('catalog_product_entity_varchar')
             ->where($db->quoteIdentifier('value') . ' LIKE ?', "%{$a}%");
$result = $db->fetchAll($select);
echo count($result);

Upvotes: 1

Related Questions