-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAWSSimpleDb.php
45 lines (37 loc) · 1.32 KB
/
AWSSimpleDb.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
<?php
abstract class Autonomic_AWSSimpleDb {
private $tableName = null;
private $sdb = null;
function __construct() {
$this->sdb = new AmazonSDB();
}
function escape_string($inp) {
if(is_array($inp))
return array_map(__METHOD__, $inp);
if(!empty($inp) && is_string($inp)) {
return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $inp);
}
return $inp;
}
function select($tableName, $cols = array('*'), $wheres = false) {
$cols = implode($cols, ", ");
$tableName = escape_string($tableName);
if ( $wheres )
{
foreach ( $wheres as $col=>$val)
{
$where[] = escape_string($col).' = "'.escape_string($val).'"';
}
$where = implode($where, " AND ");
$selector = 'SELECT '.$cols.' FROM `'.$tableName.'` WHERE '.$where;
}
else
$selector = 'SELECT '.$cols.' FROM `'.$tableName.'`';
echo $selector;
}
select("beep", array("foo","bar"));
echo "\r\n";
select("beep", array("foo","bar"), array("id" => 6));
echo "\r\n";
select("beep", array("foo","bar"), array("id" => '23 OR 1=1'));
}