Database query with $db->quote not showing required result

Hi,

I need to be able to get id value

-------------------------- CODE -------------------------------
<?php

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id');
$query->from($db->quoteName('table'));
$query->where($db->quoteName('Company')." = ".$db->quote($b));

$db->setQuery($query);
$result = $db->loadResult();
echo $result;
?>
-------------------------------------------------------------

The actual result is 2, but this code is not returning value.
e.g. Company name is "BNMU", but when I echo $db->quote($b) it renders "BNMU\n" and query doesnt return any value. If I replace it with $db->quote('BNMU'), the result is 2.

If anyone can help this, it would be really helpful.

Thanks

Best Regards
Amit
 
Hi Troester,

$b has the correct company name, I have used this:

$b = $elements ['Client']->element);
echo $b;

and it returns "BNMU", where $db->quote($b) returns "BNMU\n" and hence its not returning the desired result.

What am I doing wrong?

Regards
 
Pretty sure $b IS "BNMU\n", you won't see the new line in an echo.
Try var_dump($b);
and count the visible characters.
 
Hi,

Yeah I am sure.
b = BNMU

when I var_dump $b, its string(5) "BNMU "
(whereas I have checked multiple times that it "BNMU", but for some reason it shows blank space after "BNMU " and count it as 5 chars.

and with var_dump($db->quote($b)), its string(8) "'BNMU\n'"
(and in this one it shows 8 chars instead of 7.
 
As you can see $b is NOT "BNMU" but "BNMU"+ some space/unprintable character/whatever
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top