/
index.php
119 lines (106 loc) · 2.32 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<pre>
<?php
include "config.php";
include_once "Database.php";
$db = new Database();
/*
* Insert Example
*/
$post = array('email_user'=>'nirav.trivedi29@gmail.com','password'=>'test');
$db->insert('users',$post);
echo "Inseted Row ID is :: ".$db->InserId;
echo "<br>";
/*
* Select Example
*/
$db->select('users');
while($r=$db->fetch()){
echo $r['email_user'];
echo "<br>";
}
echo "<br>";
print_r($r);
echo "Total Rows : ", $db->NumRows();
echo "<br><br>";
/*
* Select with where
* You can use various conditions here such as like , regexp and etc...
*/
$db->select('users','*','id = 1');
$r = $db->fetch();
print_r($r);
echo "<br><br>";
/*
* Order by , group by ,limit , start examples
*/
$db->order_by = 'id ASC';
$db->start = 2;
$db->limit = 4;
$db->group_by = 'email_user';
$db->select('users');
while($r=$db->fetch()){
echo $r['email_user'];
echo "<br>";
}
echo "Total Rows : ", $db->NumRows();
echo "<br>";
/*
* Update records
*/
$post = array('email_user'=>'nirav_trivedi29@ymail.com');
$db->update('users',$post,'id = 1');
echo "Affected Rows : ", $db->affected;
echo "<br>";
/*
* Get total rows count
*/
echo "Total Rows : ",$db->Count('users','user_type = "s"');
echo "<br>";
/*
* Row count with group by
*/
$db->group_by = 'email_user';
echo "Total Rows Group by : ",$db->Count('users');
/*
* With where condition as array concate with AND
*/
$whr=array('AND'=>array('id'=>'1','user_type'=>'s'));
$db->select('users','*',$whr);
$r=$db->fetch();
print_r($r);
/*
* With where condition as array concate with AND
*/
$whr=array('OR'=>array('id'=>'0','user_type'=>'s'));
$db->select('users','*',$whr);
$r=$db->fetch();
print_r($r);
/*$a = array('AND'=>array('testa'=>'test','1'=>'a','2'=>'v'),'OR'=>array('f1'=>'v1','f2'=>'f55'),'CONCATE'=>'OR');
$where=$c='';
foreach($a as $key=>$value)
{
// echo $kkey = $key; echo "<br>";
if($key == 'CONCATE')
{
$concate = $value;
}
foreach($value as $k=>$v)
{
$cnds[] = $k.' = "'.$v.'" ';
$c .= $k.' = "'.$v.'" '.$key.' ';
}
if(count($cnds)>0)
{
$condi[] = implode(" $key ",$cnds);
$where .= implode(" $key ",$cnds);
}
unset($cnds);
}
//echo $c;
//print_r($cnds);
echo "<br>";
print_r($condi);
echo implode(" $concate ",$condi);
*/
?>
</pre>