Welcome Guest, Not a member yet? Register   Sign In
Wrong single Quote in Where Clause
#1

[eluser]coldfire82[/eluser]
I am sending to $where clause the statement: id=155 as

Code:
$this->module->saverecord('d_user_detail',$arr1," d_user_detail.userid=".$userid);

And in saverecord afterwards I call,

Code:
$bl=$this->db->update($tbname,$arr,$where);

The error I have is,
Code:
A Database Error Occurred

Error Number: 1054

Unknown column ' d_user_detail.userid=155' in 'where clause'

UPDATE `d_user_detail` SET `userid` = '155', `FIRST_NAME` = 'test', `COMPANY_NAME` = 'test' WHERE ` d_user_detail.userid=155

Did u saw the single quote (`) after where which CI adds automatically. I cannot get rid if it.

Any solution ?
#2

[eluser]coldfire82[/eluser]
I have experienced this err only in update query and not on Select query.

And, even if I add the quote explicitly around fields as

Code:
`d_user_detail`.`userid`=155

I get the same err

Code:
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 'd_user_detail`.`userid`=155' at line 1

UPDATE `d_user_detail` SET `userid` = '155', `FIRST_NAME` = 'test', `COMPANY_NAME` = 'test' WHERE ` `d_user_detail`.`userid`=155
#3

[eluser]WanWizard[/eluser]
Get rid of the space:
Code:
$this->module->saverecord('d_user_detail',$arr1," d_user_detail.userid=".$userid);
//                                               ^ this one!
#4

[eluser]coldfire82[/eluser]
[quote author="WanWizard" date="1276196879"]Get rid of the space:
Code:
$this->module->saverecord('d_user_detail',$arr1," d_user_detail.userid=".$userid);
//                                               ^ this one!
[/quote]

what about this Smile


on

Code:
$this->module->saverecord('d_user_detail',$arr1,"d_user_detail.userid=".$userid);

it gives

Code:
A Database Error Occurred

Error Number: 1054

Unknown column 'd_user_detail.userid=157' in 'where clause'

UPDATE `d_user_detail` SET `userid` = '157', `FIRST_NAME` = 'test', `COMPANY_NAME` = 'test' WHERE `d_user_detail`.`userid=157`

it added the single quote at the end of where clause.

Code:
WHERE `d_user_detail`.`userid=157`

what to do now ?
#5

[eluser]WanWizard[/eluser]
I assume you're using Active record to create the query?

It's best to split the variable:
Code:
$this->module->saverecord('d_user_detail', $arr1, "d_user_detail.userid", $userid);
so you can feed these values to $this->db->where() properly. The parser of the AR library is very simple, it can't handle a lot of where clauses, causing backticks to be inserted in the wrong place (as you have noticed). Alternatively, use the third parameter of the where() method to disable escaping.
#6

[eluser]coldfire82[/eluser]
[quote author="WanWizard" date="1276214970"]I assume you're using Active record to create the query?

It's best to split the variable:
Code:
$this->module->saverecord('d_user_detail', $arr1, "d_user_detail.userid", $userid);
so you can feed these values to $this->db->where() properly. The parser of the AR library is very simple, it can't handle a lot of where clauses, causing backticks to be inserted in the wrong place (as you have noticed). Alternatively, use the third parameter of the where() method to disable escaping.[/quote]

ActiveRecord! whats the alternate .

Here, I have to deal with more than just one variable in where clause like

Code:
$this->module->saverecord('d_user_detail', $arr1, "d_user_detail.userid=".$userid." AND x_id='1'");

and I dont want to use array('key=>'.value)pair,

then what i have to do?
#7

[eluser]coldfire82[/eluser]
disabling the escaping in 3rd parameter of where is working.
#8

[eluser]WanWizard[/eluser]
A variable number of parameters is no problem, just use an array instead:
Code:
$array = array('name !=' => 'John', 'id <' => 9, 'date >' => '20100610');
$this->db->where($array);
// produces WHERE name != 'John' AND id < 9 AND date > '20100610'




Theme © iAndrew 2016 - Forum software by © MyBB