-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Dbhelper Library
Category:Libraries | Category:Libraries::Community | Category:Libraries::Database This class is intend to help you crafting an SQL statement with funky way.
[h3]FEATURES[/h3]
- Support SELECT, INSERT, UPDATE, DELETE Statement
- Support WHERE OR.
- Support WHERE AND.
- Using native SQL statement.
- Caching query.
- Chaining method.
- Choose output : execute or just return the array of query.
- Log and error flag.
[h3]DOWNLOAD[/h3] File:DbhelperLibrary_v1.0.1.zip
[h3]VERSION HISTORY AND DESCRIPTION[/h3] [i][from version 1.0.1][/i] USAGE : [code] /* SELECT statement */ $this->load->library('dbhelper'); // Save SQL generated statement to any variable, just to see it. $query = $this->dbhelper->select_from_sometable()->query(); var_dump($query); // Execute and save it into some result variable $res = $this->dbhelper->select_from_sometable()->execute(); var_dump($res); // Select specific field only, with Limit parameter $res = $this->dbhelper->select_somefield_from_sometable(10)->execute(); var_dump($res); // Select with specific Where parameter $res = $this->dbhelper->select_somefield_from_sometable_where_id(1)->execute(); var_dump($res); // Select with Where OR and Where AND parameter $res = $this->dbhelper->select_somefield_from_sometable_where_or(array('id' => 1, 'name' => 'John Doe'))->execute(); var_dump($res); $res = $this->dbhelper->select_from_sometable_where_and(array('group_id' => 1, 'active' => 1))->execute(); var_dump($res);
/* INSERT statement */ $this->load->library('dbhelper'); // Save SQL generated statement to any variable, just to see it. $query = $this->dbhelper->insert_into_sometable_values(array('foo' => 'bar'))->query(); var_dump($query); // Execute and save it into some result variable $res = $this->dbhelper->insert_into_sometable_values(array('foo' => 'bar'))->execute(); var_dump($res); // Notice that you can specifiy any tables, including table name with '_' character in it. $res = $this->dbhelper->insert_into_my_other_table_which_had_so_long_names_values(array('foo' => 'bar'))->execute(); var_dump($res);
/* UPDATE statement */ $this->load->library('dbhelper'); // Save SQL generated statement to any variable, just to see it. $query = $this->dbhelper->update_sometable_set(array('active' => 1))->query(); var_dump($query); // Execute and save it into some result variable $res = $this->dbhelper->update_sometable_set(array('active' => 1))->execute(); var_dump($res);
/* DELETE statement. */ $this->load->library('dbhelper'); // Save SQL generated statement to any variable, just to see it. $query = $this->dbhelper->delete_from_sometable_where_id(1)->query(); var_dump($query); // Delete with specific Where parameter $res = $this->dbhelper->delete_from_sometable_where_id(1)->execute(); var_dump($res); // Delete with Where OR and Where AND parameter $res = $this->dbhelper->delete_from_sometable_where_or(array('id' => 1, 'name' => 'John Doe'))->execute(); var_dump($res); $res = $this->dbhelper->delete_from_sometable_where_and(array('group_id' => 1, 'active' => 1))->execute(); var_dump($res); [/code]
[i]Hope you find this object useful, Cheers![/i] Taufan Aditya A.K.A [b]Toopay[/b]