Select Query remove space automatically |
Hi,
I'm a new member of the forum This is my first experience with Codeigniter and my absolute first with a framework php. Today i'm writing a function in my model to get information from a mysql table. I do: $this->db->select('Web Developer'); .... But i get the error: "SELECT 'Web' 'Developer' FROM ... Column Web doesn't exist " CI has automatically replaced space with apex, splitting my single column in two columns. Why does it happen? How could i prevent it? Thank you in advance!
Hi!
You need to pass table name to select() method. Table name can't contents spaces. Look at this https://www.codeigniter.com/userguide3/d...ilder.html
(02-01-2018, 08:26 AM)Elias Wrote: Hi! No, you pass column names to the select method. For the rest you are correct. Table names as well as column names can't have a space in them
The ability to have alias names is what the code is seeing here. The space indicates that their will be an alias declared.
You will need to setup the query like so: PHP Code: $this->db->query("SELECT `Web Developer` FROM table"); (02-01-2018, 08:35 AM)Martin7483 Wrote:(02-01-2018, 08:26 AM)Elias Wrote: Hi! Yes) I confused with the get() method..)
Okay, all clear!
But MySQL allow to have space in column names. As alternative i used that: $this->db->select('`'.$job.'`', false); because $job is passed from myself, so i should be safe or i don't ? |
Welcome Guest, Not a member yet? Register Sign In |