/
Delete.php
64 lines (55 loc) · 1.27 KB
/
Delete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* @copyright Ilch 2.0
* @package ilch
*/
namespace Ilch\Database\Mysql;
use Ilch\Database\Mysql as DB;
class Delete extends QueryBuilder
{
/**
* @param \Ilch\Database\Mysql $db
* @param string|null $from table without prefix
* @param array|null $where conditions @see QueryBuilder::where()
*/
public function __construct(DB $db, $from = null, $where = null)
{
parent::__construct($db);
if (isset($from)) {
$this->from($from);
}
if (isset($where)) {
$this->where($where);
}
}
/**
* @param string $table table without prefix
* @return Delete
*/
public function from($table)
{
$this->table = (string) $table;
return $this;
}
/**
* Execute the query builder.
*
* @return integer number of deleted rows
*/
public function execute()
{
$this->db->query($this->generateSql());
return $this->db->getAffectedRows();
}
/**
* Gets delete query builder sql.
*
* @return string
*/
public function generateSql()
{
$sql = 'DELETE FROM ' . $this->db->quote('[prefix]_' . $this->table);
$sql .= $this->generateWhereSql();
return $sql;
}
}