Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
sql in database gives different result in php

I got the following sql:

SELECT COUNT(pu_id) FROM purchasing WHERE MONTH(pu_create_date)=MONTH(NOW())

In Mysql it gives the result 0 as expected.

When I put it in PHP I get the result 1 of $numMonth. This is the php code:

$database = new Database();
$db = $database->getConnection();

$stmt= $db->query('SELECT COUNT(pu_id) FROM purchasing WHERE MONTH(pu_create_date)=MONTH(NOW())') ;
$numMonth = $stmt->execute();
echo $numMonth;

Why do I get two different results?

pu_id = unique key

pu_create_date = timestamp

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You have to fetch the row from the query.

$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_NUM);
$numMonth = $row[0];
echo $numMonth;
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda