Total Complexity | 4 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Coverage | 91.67% |
Changes | 0 |
1 | <?php |
||
21 | class Insert extends AbstractBuilder |
||
22 | { |
||
23 | 1 | use Traits\Set; |
|
24 | |||
25 | /** |
||
26 | * @var string Table name |
||
27 | */ |
||
28 | protected $table; |
||
29 | |||
30 | /** |
||
31 | * {@inheritdoc} |
||
32 | * |
||
33 | * @param null $sequence |
||
|
|||
34 | * |
||
35 | * @return integer|string|array |
||
36 | */ |
||
37 | 1 | public function execute($sequence = null) |
|
38 | { |
||
39 | 1 | $result = Db::query($this->getSql(), $this->params, $this->types); |
|
40 | 1 | if ($result) { |
|
41 | 1 | return Db::handler()->lastInsertId($sequence); |
|
42 | } |
||
43 | return $result; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * {@inheritdoc} |
||
48 | * |
||
49 | * @return string |
||
50 | */ |
||
51 | 1 | public function getSql(): string |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * Turns the query being built into an insert query that inserts into |
||
60 | * a certain table |
||
61 | * |
||
62 | * Example |
||
63 | * <code> |
||
64 | * $ib = new InsertBuilder(); |
||
65 | * $ib |
||
66 | * ->insert('users') |
||
67 | * ->set('name', 'username') |
||
68 | * ->set('password', md5('password')); |
||
69 | * </code> |
||
70 | * |
||
71 | * @param string $table The table into which the rows should be inserted |
||
72 | * |
||
73 | * @return Insert instance |
||
74 | */ |
||
75 | 2 | public function insert($table): Insert |
|
79 | } |
||
80 | } |
||
81 |