Welcome Guest, Not a member yet? Register   Sign In
[solved]MYSQL ERROR 1096 - NO TABLES USED - CODEIGNITER
#1

[eluser]brucebat[/eluser]
Hi all,

Here is my Query which works fine in PHPMyAdmin and SQLYOG

Code:
SELECT intervention.department_id, department_name, COUNT(*)
FROM intervention
LEFT JOIN department ON department.department_id = intervention.department_id

GROUP BY intervention.department_id, department.department_name
ORDER BY COUNT(*) DESC
LIMIT 1

The Query + Code:

Code:
$this->db->query("
            
                                SELECT intervention.department_id, department_name, COUNT(*)
                                FROM intervention
                                LEFT JOIN department ON department.department_id = intervention.department_id
                                GROUP BY intervention.department_id, department.department_name
                                ORDER BY COUNT(*) desc
                                LIMIT 1
                            ");

            
            $result =$this->db->get();

The error message I am getting:

Quote:A Database Error Occurred

Error Number: 1096

No tables used

SELECT *

Filename: C:\xampp\htdocs\midas\system\database\DB_driver.php

Line Number: 330
#2

[eluser]Wondering Coder[/eluser]
don't see you returning your query. also add a second parameter FALSE in your query.
#3

[eluser]brucebat[/eluser]
Thanks I managed to figure it out.


It should have been :
Code:
$result = $this->db->query();

As the query is executed automatically without get() statement then when I was callign the get statement it had no values or parameters hence why it said "No Tables Found"
#4

[eluser]Aken[/eluser]
Bingo. $this->db->query() is NOT an active record function, and is meant to be used by itself. $this->db->get() is part of active record, and can be used in conjunction with select(), where(), limit(), etc.

I'd recommend using the normal query() method for most queries, unless you intend on distributing your application for use with more than one type of database. Active record can be handy, but it has its limitations and does slow down your application a minimal amount (important for high traffic sites).




Theme © iAndrew 2016 - Forum software by © MyBB