Codeigniter: how to avoid a db request returns the last statement as a key value

I execute several queries before querying the result in codeigniter:

$sql_drop_temptable = "...blabla..."; $sql_prepare = "it creates a temporary table; where I sum up later..."; $sql_summe = " select sec_to_time(sum(time_to_sec(summands))) from workday;"; $query = $this->db->query($sql_drop_temptable); $query = $this->db->query($sql_prepare); $query = $this->db->query($sql_summe)->row(); var_dump($query); 

How can I avoid getting the last sql statement ($ sql_summe) as a keyword in the result set? It’s hard for me to get the result in a scalar. The result is as follows:

 object(stdClass)[41] public 'sec_to_time(sum(time_to_sec(summands)))' => string '00:23:54' (length=8) 

I usually see column names as key values. But there is no column name in this because of the sum function, so it uses the sql operator as the key value. (?)

Thanks.

+4
source share
1 answer

Just rename it using AS in your query:

 SELECT sec_to_time(sum(time_to_sec(summands))) AS something ... 

And now something will be the key.

+1
source

Source: https://habr.com/ru/post/1501071/


All Articles