Welcome Guest, Not a member yet? Register   Sign In
Database Error: 1064
#1

[eluser]Unknown[/eluser]
Well hoping I can get some help, I've searched forums and googled this any way I can think of but haven't found a solution.

I have installed XMAMPP:

XAMPP 1.7.3, including:
Apache 2.2.14 (IPv6 enabled) + OpenSSL 0.9.8l
MySQL 5.1.41 + PBXT engine
PHP 5.3.1
phpMyAdmin 3.2.4
Perl 5.10.1
FileZilla FTP Server 0.9.33
Mercury Mail Transport System 4.72

I have also downloaded and have running CODEIGNITER 1.72. I have my basic application up and connecting to my database. I had a custom sql I have written to select data that instead of using the active record pattern. I can run this query directly on the DB and get results back but when I run from my code i'm getting Error Number: 1064.

Below is the details echo'd out on the error. I'm also include the code function that has the db call.

ERROR Message:
Quote:A Database Error Occurred
Error Number: 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 '.ID, `e`.`cuid`, `e`.`firstname`, `e`.`lastname`, `e`.`Title`, `e`.`hourlyRate`,' at line 2

SELECT * FROM (`SELECT` e.ID, `e`.`cuid`, `e`.`firstname`, `e`.`lastname`, `e`.`Title`, `e`.`hourlyRate`, `e2`.`cuid` AS managerID, `a`.`companyName`, `l`.`addressLine1`, `l`.`state`, `l`.`country`, `e`.`resourceType`, `e3`.`cuid` AS supervisorID FROM employee e LEFT JOIN employee e2 ON e.managerID = e2.ID LEFT JOIN employee e3 ON e.supervisorID = e3.ID LEFT JOIN agency a ON e.agencyID = a.ID LEFT JOIN location l ON e.locationID = l.ID)

CODE BLOCK:
Code:
function index() {
        $data['title'] = "Employee";
        $data['heading'] = "Employees";
        $sql = "SELECT e.ID, e.cuid, e.firstname, e.lastname, e.Title, e.hourlyRate, \n"
        . " e2.cuid AS managerID, a.companyName, l.addressLine1, l.state, \n"
        . " l.country, e.resourceType, e3.cuid AS supervisorID \n"
        . " FROM employee e \n"
        . " LEFT JOIN employee e2 ON e.managerID = e2.ID \n"
        . " LEFT JOIN employee e3 ON e.supervisorID = e3.ID \n"
        . " LEFT JOIN agency a ON e.agencyID = a.ID \n"
        . " LEFT JOIN location l ON e.locationID = l.ID";
        $data['query'] = $this->db->get($sql);
        $this->load->view('employee_view', $data);
    }
#2

[eluser]danmontgomery[/eluser]
[quote author="Eric Mahaffey" date="1277497088"]Well hoping I can get some help, I've searched forums and googled this any way I can think of but haven't found a solution.[/quote]

Have you tried the user guide?

http://ellislab.com/codeigniter/user-gui...eries.html

Code:
$data['query'] = $this->db->get($sql);
should be
Code:
$data['query'] = $this->db->query($sql);
#3

[eluser]Unknown[/eluser]
Thanks for the help, I completely missed changing that when I decided not to use the active record approach.

Thanks again,

Eric




Theme © iAndrew 2016 - Forum software by © MyBB