Codeigniter - setting dbprefix triggers [Cannot modify header information - headers already sent]

53 views Asked by At

I am appending custom selects and table aliases into the query. Used {PRE} to append prefix to table names in the custom query but it was also adding the prefix to alias in select. if I add

{PRE}countries AS c  // output mydb_countries AS c

So, when I pass an array to select() method :

$select = ['`c`.`Name` AS TITLE'];
$this->db->select($select);

//output select 'mydb_c.Name' AS TITLE from mydb_countries AS c

//expected select 'c.Name' AS TITLE from mydb_countries AS c

So, I tried to get rid of {PER} and change the dbprefix :

$bkp_prefix = $this->db->dbprefix;

$this->db->set_dbprefix(''); // Setting prefix to empty

$this->db->select($select); // manually add prefix to table names

$results = $this->db->get()->result_array();

$this->db->set_dbprefix($bkp_prefix); // Revert prefix to original state

Results returned are accurate by I get the warning :

Severity: Warning Message: Cannot modify header information - headers already sent by(output started at {file path}) Filename: core/Common.php Line Number: 573 Backtrace:

Which create problem while writing the results to CSV. Although, When I comment : //$this->db->set_dbprefix('');

Warning disappears.

P.S. There is no echo,printr,var_dump any where near my code and the warning i get is before I send my results to generateCSV() method which is in separate module.

0

There are 0 answers