· 7 years ago · Jan 12, 2019, 07:22 AM
1<?php
2
3# through DSN
4$db = connect(...);
5
6$tbl = 'my_table';
7$col = 'my_column';
8
9
10
11serialize($db); # export scheme
12unserialize($str); # import scheme
13
14$db[$tbl]; # retrieve the table handle for $tbl, warn if not exists
15$db[$tbl] = array(); # create the table with the given columns, warn if exists already
16$db[$tbl] = ''; # rename the table or drop if empty; warn if not exists (from) or already exists (to)
17
18isset($db[$tbl]); # check table existence without warnings
19unset($db[$tbl]); # drop the table, warn if not exists
20
21
22$db[$tbl]->$method(...); # delegate table-method, i.e. drop($tbl, ...) or rename($tbl, ...)
23$db[$tbl]->select($fields, $where, $options); # => select($tbl, ...)
24$db[$tbl]->insert($values, $pk_for_pgsql?); # => insert($tbl, ...)
25$db[$tbl]->update($fields, $where, $limit); # => update($tbl, ...)
26$db[$tbl]->delete($where, $limit); # => delete($tbl, ...)
27
28$db[$tbl]->rename($to); # => rename($tbl, ...)
29$db[$tbl]->drop(); # => drop($tbl)
30
31$db[$tbl]->select()->$method(...); # delegate result-method, i.e. fetch_all($res, ...) or result(...)
32$db[$tbl]->add_column($col, $name, $type); # => add_column($tbl, ...)
33$db[$tbl]->rename_column($col, $to); # => rename_column($tbl, ...)
34$db[$tbl]->change_column($col, $type); # => change_column($tbl, ...)
35$db[$tbl]->remove_column($col); # => remove_column($tbl, ...)
36
37
38
39serialize($db[$tbl]); # export data-only
40unserialize($db[$tbl]); # import data-only
41
42$db[$tbl][$col]; # retrieve field handle for $col, warn if not exists
43$db[$tbl][$col] = ''; # rename the column or remove if empty; warn if not exists (from) or already exists (to)
44$db[$tbl][$col] = array(); # add or change column, warn if already exists or cannot be crafted
45
46isset($db[$tbl][$col]); # check column existence without warnings
47unset($db[$tbl][$col]); # remove column, warn if not exists
48
49$db[$tbl][$col]->$method(...); # delegate column-method, rename($tbl, $col, ...) => rename_column($tbl, $col, ...)
50
51
52# special cases, the $hash is generated from given arguments, i.e. $hash = "$tbl.$col.$name"
53$db[$tbl][$col]->index($name, $unique); # => add_index($tbl, $hash, $col, ...)
54$db[$tbl][$col]->unindex($name); # => remove_index($hash)