CodeIgniter Forums
[split] Annoying column? CodeIgniter 3.1.9 released - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: [split] Annoying column? CodeIgniter 3.1.9 released (/showthread.php?tid=72635)



[split] Annoying column? CodeIgniter 3.1.9 released - buzzlee - 01-16-2019

$primary_column_has_space = "annoying column";
$value = "value of column";
$data = array("column_one"=>"value one");

$this->db->where("`".$primary_column_has_space."`", $value);
$this->db->update("annoying_table", $data);
echo $this->db->last_query();
Output : Update `annoying_table` set `column_one`='value one' where `annoying column` 'value of column';


$this->db->where("`".$primary_column_has_space."` =", $value);
$this->db->update("annoying_table", $data);
echo $this->db->last_query();
Output : Update `annoying_table` set `column_one`='value one' where `annoying` `column` = 'value of column';


$this->db->where("`".$primary_column_has_space."` = ".$value);
$this->db->update("annoying_table", $data);
echo $this->db->last_query();
Output : Update `annoying_table` set `column_one`='value one' where `annoying` `column` = 'value of column';



Codeigniter is not support for update where column name has space? any solution?


RE: [split] Annoying column? CodeIgniter 3.1.9 released - InsiteFX - 01-17-2019

A space in any database field name / column name is not allowed!

Use an underscore annoying_column

If this is for CodeIgniter 3.1.9 then you post this in the wrong Forum Topic.


RE: [split] Annoying column? CodeIgniter 3.1.9 released - php_rocs - 01-17-2019

@buzzlee,

What database are you using? Mysql? Postgresql? From what I understand MySQL does allow spaces in column names. Putting spaces in column names is BAD practice.


RE: [split] Annoying column? CodeIgniter 3.1.9 released - InsiteFX - 01-17-2019

To use in a mysql query you would need to escape the "annoying column"

using backtick marks `annoying column`