Parenthesis between WHERE are not working
Hi!
I'm using PHP MySQLi Class v1.5.2 and this:
$db->select('column')->from('table'); $db->where('foo', 15); $db->open_where(); $db->or_where('foo <', 15); $db->where('bar >=', 15); $db->close_where();
echo $db->dryrun()->fetch()->last_query();
Is echoing:
SELECT column
FROM table
WHERE foo = '15' OR foo < '15' AND bar >= '15')
The first parenthesis is missing.
Comments (4)
-
repo owner -
SELECT `column` FROM `table` WHERE `foo` = 15 OR (`foo` < 15 AND `bar` >= 15)
According to this link
Actually this is what return
SELECT `column` FROM `table` WHERE `foo` = 15 OR `foo` < 15 AND `bar` >= 15)
Ps. Sorry that I have created this topic as anonymous.
-
repo owner Hi
I am unable to replicate the issue.
Consider this
$db->from('tbladdresses'); $db->where('customerid', 7); $db->open_where(); $db->or_where('customerid' , 10); $db->where('title', 'President'); $db->close_where(); $rows = $db->fetch(); echo $db->last_query();
This produces
SELECT * FROM tbladdresses WHERE customerid = '7' OR ( customerid = '10' AND title = 'President')
Let me know the exact code that you are trying so that I can try to replicate the issue
-
This
$db->select('column'); $db->from('table'); $db->where('foo', 15); $db->open_where(); $db->or_where('foo', 15); $db->where('bar >=', 15); $db->close_where(); echo $db->dryrun()->fetch()->last_query();
Produces
SELECT `column` FROM `table` WHERE foo = '15' OR ( foo = '15' AND bar >= '15')
Which is correct, but this
$db->select('column'); $db->from('table'); $db->where('foo', 15); $db->open_where(); $db->or_where('foo >', 15); $db->where('bar >=', 15); $db->close_where(); echo $db->dryrun()->fetch()->last_query();
Produces
SELECT `column` FROM `table` WHERE foo = '15' OR foo > '15' AND bar >= '15')
instead of
SELECT `column` FROM `table` WHERE foo = '15' OR (foo > '15' AND bar >= '15')
Where is the starting "(" ?
The open_where() was omitted.
Ps. in v1.5.3 is the same thing.
- Log in to comment
What is the expected mysql query ?