Welcome Guest, Not a member yet? Register   Sign In
Weird database error or bug?
#1

[eluser]PODz_EN_Co.[/eluser]
I have this error when using the database class:

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 '? AND er.createstatus = 'ACTIVE' AND c.createstatus = 'ACTIVE' ' at line 11

SELECT c.currencydesc as currencyfrom, c2.currencydesc as currencyto, er.amount, er.createdate, er.createby FROM exchangerate er INNER JOIN currency c ON c.currencyid = er.currencyidfrom INNER JOIN currency c2 ON c2.currencyid = er.currencyidto WHERE er.createby = ? AND er.createstatus = 'ACTIVE' AND c.createstatus = 'ACTIVE' AND c2.createstatus='ACTIVE'

This is the model that calls it:
Code:
function currentRates(){
        $createby = $this->session->userdata('userid');
        $SQL = "SELECT c.currencydesc as currencyfrom,
                       c2.currencydesc as currencyto,
                       er.amount,
                       er.createdate,
                       er.createby
                 FROM exchangerate er
                INNER JOIN currency c
                 ON c.currencyid = er.currencyidfrom
                INNER JOIN currency c2
                 ON c2.currencyid = er.currencyidto
                WHERE er.createby = ?
                 AND er.createstatus = 'ACTIVE'
                 AND c.createstatus = 'ACTIVE'
                 AND c2.createstatus='ACTIVE'";
        $this->result = $this->db->query($SQL, $createby);
        return $this->result;
    }

But when I query through the mySQL browser itself, the query works... Is this a bug in codeigniter?
#2

[eluser]davidbehler[/eluser]
second parameter of $this->db->query() has to be an array I think.

Try this:
Code:
$this->result = $this->db->query($SQL, array($createby));
#3

[eluser]rogierb[/eluser]
From the userguide:
"<i>The question marks in the query are automatically replaced with the values in the <b>array</b> in the second parameter of the query function.</i>"

Edit: ah, to late...
#4

[eluser]PODz_EN_Co.[/eluser]
[quote author="waldmeister" date="1265052013"]second parameter of $this->db->query() has to be an array I think.

Try this:
Code:
$this->result = $this->db->query($SQL, array($createby));
[/quote]
this code returns false data.
#5

[eluser]rogierb[/eluser]
Quote:this code returns false data.

Well that is helpfull... If you want us to help you have to provide more information.

So please post the error message or the query generated by CI ($this->db->last_query());
#6

[eluser]PODz_EN_Co.[/eluser]
I don't know why but the error is gone. I did not change anything.
#7

[eluser]PODz_EN_Co.[/eluser]
Hello, i've come again of the same error:
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 '? AND createstatus = 'ACTIVE'' at line 1

SELECT usertypeid, usertypedesc FROM usertype WHERE parentusertypeid >= ? AND createstatus = 'ACTIVE'

Code:
function listUserTypes($parentUserTypeId=0){
        $SQL = "SELECT usertypeid, usertypedesc FROM usertype ";
        if($parentUserTypeId == 0){
            $SQL .= " WHERE parentusertypeid >= ? ";
        } else {
            $SQL .= " WHERE parentusertypeid > ? ";
        }
        $SQL .= " AND createstatus = 'ACTIVE'";
        $this->result = $this->db->query($SQL, $parentUserTypeId);
        return $this->result;
    }

Making the 2nd argument to array($parentUserTypeId) returns false data. I know this should be correct but why is the error prompting?

By the way, I'm passing this call:
Code:
$parentUserTypeId = 3;
$this->membership->listUserTypes($parentUserTypeId);

Thanks in advance.




Theme © iAndrew 2016 - Forum software by © MyBB