Is the syntax of the database query OK?

-2

I have this query to the DB, but I do not know if the syntax is ok

    $this->db->select('rut_usu, fecha_ini, fecha_ter');
    $this->db->from('hoario');
    $this->db->where('rut_usu=',$rut_usu,'AND fecha_ini=',$fecha_ini,'AND fecha_ter=',$fecha_ter);
    $consultar = $this->db->get();
    
asked by Kvothe_0077 21.09.2017 в 21:07
source

1 answer

0

Are you using CodeIgniter?

In that case you have a syntax error in:

   $this->db->where('rut_usu=',$rut_usu,'AND fecha_ini=',$fecha_ini,'AND fecha_ter=',$fecha_ter);

The correct way to write it is:

    $this->db->where("rut_usu='".$rut_usu."' AND fecha_ini='".$fecha_ini."' AND fecha_ter='".$fecha_ter."'");

Notice that the values within the SQL statement must be enclosed in quotation marks. And what have you used ',' to concatenate, instead of '.'

Another way to write it is:

$this->db->where('rut_usu', $rut_usu);
$this->db->where('fecha_ini', $fecha_ini);
$this->db->where('fecha_ter', $fecha_ter);

And another:

$array = array('rut_usu =' => $rut_usu, 'fecha_ini =' => $fecha_ini, 'fecha_ini =' => $fecha_ini);
$this->db->where($array);
    
answered by 22.09.2017 / 05:14
source