-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDbQueryBuilder.php
44 lines (37 loc) · 1.05 KB
/
DbQueryBuilder.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
<?php
require_once 'DbExpression.php';
class DbQueryBuilder {
private $_schema;
private $_table;
private $_bind_params = array();
public function setSchema($schema) {
$this->_schema = sprintf('`%s`', (string)$schema);
return $this;
}
public function setTable($table) {
$this->_table = sprintf('`%s`', (string)$table);
return $this;
}
public function insert($params) {
$template = 'INSERT INTO %s (%s) VALUES (%s)';
$dest = implode('.', array($this->_schema, $this->_table));
$keys = $values = array();
foreach ($params as $key => $param) {
$keys[] = sprintf('`%s`', $key);
if ($param instanceof DbExpression) {
$values[] = $param;
}
else {
$placeholder = sprintf(':%s', $key);
$values[] = sprintf(':%s', $key);
$this->_bind_params[$placeholder] = $param;
}
}
return sprintf($template, $dest, implode(', ', $keys), implode(', ', $values));
}
public function update() {
}
public function getBindParams() {
return $this->_bind_params;
}
}