0

How can i use greater or less than in sql where conditions (<, >, <=, >=) on ImpressPages 4.x. I tried something like following but i got error on ipDb()->update() and ipDb()->delete() functions:

ipDb()->delete('Persons', array('age <=' => 18));

ipDb()->delete('Persons', array('age >' => 80));

ipDb()->delete('Persons', array('age <' => 25));

ipDb()->delete('Persons', array('age >=' => 41));

The Error:

Column not found: 1054 Unknown column 'age <=' in 'where clause'' in

Bora
  • 10,529
  • 5
  • 43
  • 73

1 Answers1

1

ipDb() provides you very nice methods to cover 90% of your taks. But they don't cover all 100%. If you need to do the join or anything else more complex, use ipDb()->execute($sql, $paremters). This way you can execute any kind of query.

In your particular case, ImpressPages has sqlMinAge and sqlMaxAge functions that may suit your case http://www.impresspages.org/docs/class-ip-db. If not, use raw SQL and ipDb()->execute method.

Mangirdas Skripka
  • 1,647
  • 1
  • 15
  • 14
  • Like this? `ipDb()->execute("UPDATE Persons SET status = 0 WHERE age < = :age", array('age' => $age));` Should i use `execute` the query? – Bora Oct 27 '14 at 10:40
  • Yes like this. Isn't it working for you? There are two things I'm concerned: 1 No prefix on table name. Use $table = ipTable('Persons'); ipDb()->execute("UPDATE $table SE ... 2. I'm not sure if MySQL supports the space here "< =" But in general the idea is right. Turn on error reporting if you don't see any error. – Mangirdas Skripka Oct 27 '14 at 14:43
  • It's working well. I just write as sample. Yes i mistyped, should be `age <= :age` – Bora Oct 27 '14 at 16:32