-
Notifications
You must be signed in to change notification settings - Fork 6
sql
Zimo Xiao edited this page May 30, 2018
·
7 revisions
- select - do a SELECT query
- sql::select($table)
-
- Except for select()/fetch()/count(), everything is optional.
-
sql::select('table_name') ->where('a=? and b=?',[$a,$b]) //second parameter is optional ->limit([2,5]) //limit can be int ->order('a_column') ->by('desc') ->fetch(); //if you only need the number of results, use count() instead //the above code generates a query like this: //SELECT * FROM table_name WHERE a=? AND b=? LIMIT 2,5 ORDER a_column BY desc
- returns: array (single layer if there is only one result)
- insert - insert data to SQL
- sql::insert($table)
-
- insert 2 arrays as seperate lines
-
sql::insert('table_name')->this([$array_1, $array_2]); //each array should match your table structure
- returns: NULL
- update - update data in SQL
- sql::update($table)
-
-
//mode 1 sql::update('table_name')->this([ 'column_name_1'=>'value_1', 'column_name_2'=>'value_2' ])->where('a=? and b=?',[$a,$b])->limit(3)->execute(); //mode 2 sql::update('table_name') ->this('column_name_1 = "hi", column_name_2 = ?',[$value_2]) ->execute();
- returns: NULL
-
- delete - delete data
- sql::delete($table)
-
-
sql::delete('table_name')->where('a=? and b=?',[$a,$b])->limit(3)->execute();
- returns: NULL
-
- run - run a query string
- sql::run($query)
-
-
sql::run('select from a');
- returns: NULL
-