Welcome Guest, Not a member yet? Register   Sign In
Select Query remove space automatically
#1

Hi,
I'm a new member of the forum Smile

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!
Reply
#2

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 Smile
Reply
#3

(02-01-2018, 08:26 AM)Elias Wrote: 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 Smile

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
Reply
#4

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"); 
Reply
#5

(02-01-2018, 08:35 AM)Martin7483 Wrote:
(02-01-2018, 08:26 AM)Elias Wrote: 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 Smile

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


Yes) I confused with the get() method..)
Reply
#6

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 ?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB