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

152
Visualizações
Add mysqli options in Codeigniter 4

I have several fields in my database that are DECIMAL(10,2) or INT values, when I return the results everything is returned as string.

Example:

    $sql = "SELECT id, operacion_id FROM operaciones";
    $query = $this->db->query($sql);
    $result = $query->getResultArray();

    return $this->response->setStatusCode(200)
                    ->setContentType('application/json')
                    ->setJSON($result);

And that returns:

[{
    "id": "31",
    "operacion_id": "ES-2021-0031"
},
{
    "id": "30",
    "operacion_id": "ES-2021-0030"
}]

I tried to put directly in system\Database\MySQLi\Connection.php connect() method:

$this->mysqli->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true);

This works well but I know that it is not upgrade safe.

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

0

You should be able to apply this option to mysqli property of your database object.

$this->db->mysqli->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true);
// and then run your queries
$query = $this->db->query($sql);

When working with prepared statements, you don't have to apply this setting as prepared statements always return the data in the correct type.

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