Problem showing a "select Count(*)" in PHP

Asked

Viewed 604 times

-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 run this SQL statement by PHP the return is 0.

What is wrong?

  • Maybe use fetchOne(); and merge a result var_dump

  • How do I do this in PHP? I Googled and only got results from Pyton

  • that what the var_dump ? var_dump($variable);

  • didn’t work, bugged everything

  • Bugle not It prints a dump of the variable

  • it is easier to update the question with the return

  • and of course already takes the opportunity to put in Portuguese .... Oce is in the stack Brazil

  • string(1) "0" from that

  • ta using some orm or as ta doing ?

  • is a platform called Gesior, is a gaming site. It uses PDO.

Show 5 more comments

1 answer

2

You cannot call a method inside a string that way because php thinks a property is being accessed and an 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 case use keys around the method:

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

Or concatene call:

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

Example

Strings - manual

Browser other questions tagged

You are not signed in. Login or sign up in order to post.