Recently, I had some toughts about creating a wrapper to combinate SQL clauses more easily.
I decided to try how it would work out for the module i'm currently working on.
An example for usage:
Code: Select all
$sql = new SQLGenerator();
$sql->select = array("u.id", "p.name");
$sql->join = array("LEFT JOIN ".cms_db_prefix()."user_location AS l ON u.id = l.user");
$sql->where = array("l.type = 1");
$sql->limit = 30;
print_r( $sql->UserQuery() ); //when called will return (only) a formatted SQL query
What makes it special is demonstrated in the following example:
Code: Select all
if(!empty($params["imageonly"]))
{
$sql->from[] = "cms_module_uploads_categories AS c";
$sql->from[] = "cms_module_uploads AS up";
$sql->where[] = "u.id = c.upload_category_name";
$sql->where[] = "c.upload_category_id = up.upload_category_id";
$sql->groupby[] = "up.upload_category_id";
}
This creates a flexible whay to deal with parameters and SQL.
Here is a draft class that contains the two functions: There could be even more functionalities when this module was worked out providing more (SQL) flexibility, robustness and error prevention.
I would like to know what you readers think of this module/plugin idea.
Would it be a needed and usefull addition?
I haven't found any projects like it..
I would like to repeat that this is just a draft. If developed, ideas and suggestions will help make it better.
Greetings,
Jurrian