bgultekin / laravel4-datatables-package

Server-side handler of DataTables Jquery Plugin for Laravel 4
267 stars 108 forks source link

Search return "Error connecting to database" #158

Open miamilabs opened 10 years ago

miamilabs commented 10 years ago

Dear Community,

i use Datatables and i had some troubles on testing. the Return of json works fine as soon i am doing some search in DataTables i get error "Error connecting to database". The configuration of Laravel are OK.

After some search i find out which query is DataTables doing : "select count(_) as aggregate from (select '1' as row from TVINFORMATION inner join LOCATION on TVINFORMATION.location = LOCATION.location_id where (LOWER(_) LIKE %13%)) AS count_row_table)"

If i use that query in Phpmyadmin : " #1064 - 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 '*) LIKE %13%)) AS count_row_table) LIMIT 0, 25' at line 1 "

My Model code is : $users = $this::select()->join($this->join_table, $this->table . '.location', '=', $this->join_table . '.location_id'); return $dataTables = Datatables::of($users) ->make(true);

Would be great if some one would give me some advice.

Thank you.

Best Regards Paul

phazei commented 10 years ago

Well, there is an error in the first query with "LOWER()" it needs an argument. But in the quote from phpmyadmin near '*) LIKE %13% ... it seems to be from a different query as it starts with an asterisk which isn't in the other one.

Seems it's missing the column name. That can be caused by a number of reasons. If you are using fullDataSupport then it's likely your "data" column isn't there in the datatables js config. Otherwise if you're not, then the column needs to be explicitly selected in the query select statement in the proper order of the columns requested from the plugin.