Welcome Guest, Not a member yet? Register   Sign In
Or_where Help
#1

[eluser]derekmichaeljohnson[/eluser]
I'm trying to form a query like this:
Code:
SELECT *
WHERE `city` = `dallas` AND (`type` = `a` OR `role` = `lead`)
FROM `users`
Is this possible with the active record class?
#2

[eluser]Jbeasley6651[/eluser]
Code:
$where = "city='dallas' AND type='a' OR role='lead'";

$this->db->where($where);
$this->db->get('users');
#3

[eluser]KingSkippus[/eluser]
Just a short best practice note. Use backticks in MySQL for database, table, or column names, but use single quotation marks for string literals. Your original query should have been:

Code:
SELECT *
FROM `users`
WHERE `city` = 'dallas' AND (`type` = 'a' OR `role` = 'lead')
#4

[eluser]Jbeasley6651[/eluser]
King,

Is there a difference in performance, and if so is it noticeable?
#5

[eluser]KingSkippus[/eluser]
No, at least not that I know of, and if so, it's probably minuscule. It's for portability. Not just for your code, though that's a definite bonus in case you ever decide you want your database to live on another DBMS, but for your skills as well. Using well-established standards will allow you to easily shift between MySQL, Oracle, SQL Server, PostgreSQL, Sybase, or whatever.




Theme © iAndrew 2016 - Forum software by © MyBB