There are several ActiveRecord styled query builder libraries out there. Some are stand alone and some come built into frameworks. However, they really have trouble with WHERE a
This is part of my ActiveRecord class, I don't handle sub queries (I don't even bother):
public function Having($data, $operator = 'LIKE', $merge = 'AND')
{
if (array_key_exists('query', $this->sql) === true)
{
foreach ($data as $key => $value)
{
$this->sql['having'][] = ((empty($this->sql['having']) === true) ? 'HAVING' : $merge) . ' ' . $this->Tick($key) . ' ' . $operator . ' ' . $this->Quote($value);
}
}
return $this;
}
public function Where($data, $operator = 'LIKE', $merge = 'AND')
{
if (array_key_exists('query', $this->sql) === true)
{
foreach ($data as $key => $value)
{
$this->sql['where'][] = ((empty($this->sql['where']) === true) ? 'WHERE' : $merge) . ' ' . $this->Tick($key) . ' ' . $operator . ' ' . $this->Quote($value);
}
}
return $this;
}
One other thing that you may consider is having a customHaving() and customWhere() methods.