Problem displaying a "select count (*)" in PHP

-1
$result = $SQL->query("select count(*) AS codes_count from gamecodes WHERE gamecode='.$SQL->quote($gamecode).' AND alreadyused='N';")->fetch();
$counts = $result['codes_count'];
echo $counts;

When I run this SQL statement in the database, the return is 1 . When I execute this SQL statement by PHP the return is 0 .

What's wrong?

    
asked by anonymous 12.09.2014 / 20:27

1 answer

2

You can not call a method inside a string in this way because php thinks a property is being accessed and a notice is generated: Notice: Undefined property Classe::$propriedade

echo "$SQL->quote($gamecode) ...";

Your query is interpreted as:

select count(*) AS codes_count from gamecodes WHERE gamecode='.(valor).' AND alreadyused='N';

To fix this, in the case use keys around the method:

 echo "{$SQL->quote($gamecode)} ...";

Or concatenate call:

echo 'algo '. $SQL->quote($gamecode) . ' mais alguma coisa';

Example

Strings - manual

    
12.09.2014 / 20:40