0

I'm writing to you today because i've got question about the Method FetchAll() in PHP.

I'm currently developing Web API and I would like to set GetSomething() method using Json_encode.

The thing is when I m using it those returning fields as String type.. I found couple way to fix it as JSON_NUMERIC_CHECK but i feel like missing something.. May be should I instance new object and call the constructor before returning json_encode() ?

Thanks for reading me ! :)

  public function GetProduit()
    {

        $ReqClient = "SELECT * FROM dbo.Produit";
        $MailVerif = $this->connexion->prepare($ReqClient);
        $MailVerif->execute(array());
        $result = $MailVerif->fetchAll();

        if (!$result) {
            throw new Exception('Nothing set');
        }
    
       echo json_encode($result, JSON_NUMERIC_CHECK);
    }
  • Does this answer your question? [MySQL integer field is returned as string in PHP](https://stackoverflow.com/questions/5323146/mysql-integer-field-is-returned-as-string-in-php) - If `JSON_NUMERIC_CHECK` fixes your issue, then go for it. If you have strings that should be strings while it can contain numeric values, then you need to do some manual intervention. – M. Eriksson Feb 17 '22 at 13:40
  • what database you are using? dbo is quite a strange database name for mysql – Your Common Sense Feb 17 '22 at 14:29

0 Answers0