• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Query not working in CI 1.7 anymore?

#1
[eluser]mvdg27[/eluser]
Hi guys,

I'm updating a website right now, and I'm actually recreating a lot of code. Off course I use my old code as a reference. The old code was based on CI 1.6, and the new code is based on CI 1.7

Now I'm running into a problem with a query that used to work without any problems on 1.6, but now produces an error.

The following statement contains the error:

Code:
$this->db->select('lists.id, lists.title, users.username, count(list_views.list_id) AS views');

When I leave out the 'count' there is no error at all:

Code:
$this->db->select('lists.id, lists.title, users.username, list_views.list_id');

The error I'm receiving is:

Code:
Error Number: 1109</p><p>Unknown table 'count(list_views' in field list

Any idea how this error may be fixed?

Thanks! Michiel

#2
[eluser]GSV Sleeper Service[/eluser]
try adding FALSE as a second parameter to the db->select call.
Quote:$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.

#3
[eluser]xwero[/eluser]
It seems that the table protector functionality is too eager. As a quickfix you can add FALSE as the second parameter of the select method. This prevents the method to protect the identifiers.

I never encountered this problem but i'm using a table alias if i have to specify the table of the field. Maybe that could be another way to solve this problem?

#4
[eluser]mvdg27[/eluser]
Adding false as a second parameter solved the problem indeed!

@xwero: how do you use a table alias?

Thanks! Michiel

#5
[eluser]xwero[/eluser]
like you are using field aliases
Code:
$this->db->from('table t1');

#6
[eluser]Phil Sturgeon[/eluser]
Remember table aliases are escaped if you put them in the get, but works fine in the from().


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.