Welcome Guest, Not a member yet? Register   Sign In
Protect_identifiers of From/Get changed from 2.0.2
#1

Hi,

i was using this code and it works in 2.0.2

$query = $this->db->get($var.'foo as foo');
let's say that $var is a shortcode for example a tag like "1X"

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM (`1Xfoo` as foo)

Because i join some general tables with some prefixed, i used alias "as foo" so i can do my queries with foo.XYZ instead of putting encapsulating a string $var (i use single quotes for perfomance and it's pretty annoying) in front of every foo.

Now i put this to ovveride the problem
$db['local']['_protect_identifiers']= FALSE;

What am doing i wrong?
Is it bad habit to give alias to FROM or is better to put doublequotes and $var?
Why is this actually changed? Am i secure with protect identifiers disabled?

Thanks,
J
Reply
#2

It's possible the problem is in another part of your query (e.g. directly before the portion quoted in the error message). Usually the best thing to do would be to get the query being sent to the database (preferably using a debugger) and execute it in a SQL client or from the command line to see if you can get a better error message. In some cases it may be obvious once you see the generated query.

Is disabling protect identifiers actually fixing the issue?

In general, the single quotes vs. double quotes is not going to make a difference in the result of your query unless you're handling data which contains those characters. It's also not likely to make a significant difference in performance (see http://stackoverflow.com/questions/34462...ngs-in-php ).
Reply
#3

you can have an alias without the as keyword like " ... from table t1 ...." so you can try this

$this->db->get($var.'foo foo');

Reply




Theme © iAndrew 2016 - Forum software by © MyBB