1+ <?php
2+
3+ namespace qwerty \Config ;
4+
5+ Abstract class Sql implements SqlPattern {
6+
7+ private $ connetction ;
8+ private $ sql ;
9+ private $ query ;
10+ private $ rt ;
11+ private $ quote ;
12+ private $ res ;
13+
14+ public function __construct ($ connetction )
15+ {
16+ $ this ->connetction = $ connetction ;
17+ }
18+
19+ public function Select_ch ($ table ,$ data = array ())
20+ {
21+ array_keys ($ data );
22+ $ qt = "" ;
23+ foreach (array_merge ($ data ) as $ item ){
24+ $ qt .= $ item .", " ;
25+ }
26+ $ res = rtrim ($ qt ,", " );
27+
28+ $ this ->sql = "Select " .$ res ." from " .$ table ;
29+ $ this ->query = $ this ->connetction ->prepare ($ this ->sql );
30+ $ this ->query ->execute ();
31+
32+ while ($ this ->rt = $ this ->query ->fetchAll ()) {
33+ return $ this ->rt ;
34+ };
35+ // TODO: Implement Select_ch() method.
36+ }
37+
38+ public function Select_all ($ table )
39+ {
40+ $ this ->sql = "Select * from " .$ table ;
41+ $ this ->query = $ this ->connetction ->prepare ($ this ->sql );
42+ $ this ->query ->execute ();
43+
44+ while ($ this ->rt = $ this ->query ->fetchAll ()) {
45+ return $ this ->rt ;
46+ };
47+
48+
49+ }
50+
51+ public function Select_wh ($ table ,$ data = array (),$ con = array (),$ if = array ()){
52+
53+
54+ $ q = "" ;
55+ $ i = 0 ;
56+ $ b = 1 ;
57+ foreach ($ data as $ x => $ val ) {
58+ $ q .= " $ x " .$ con [$ i ]." $ val " .$ if [$ b - 1 ];
59+ $ i ++;
60+ }
61+
62+ $ res = rtrim ($ q ,"AND " );
63+
64+
65+ $ this ->sql = "SELECT * FROM " .$ table ." WHERE " . $ res ;
66+
67+ $ this ->query = $ this ->connetction ->prepare ($ this ->sql );
68+ $ this ->query ->execute ();
69+
70+ while ($ this ->rt = $ this ->query ->fetchAll ()) {
71+ return $ this ->rt ;
72+ };
73+
74+
75+
76+ }
77+
78+ public function Insert ($ table , $ data = array ())
79+ {
80+ $ quote = "" ;
81+ foreach (array_keys ($ data ) as $ item ){
82+ $ quote .= $ item ." = : " . "$ item, " ;
83+ }
84+ $ res = rtrim ($ quote ,", " );
85+
86+ $ this ->sql = "INSERT INTO " .$ table ." SET " . $ res ;
87+ $ this ->query = $ this ->connetction ->prepare ($ this ->sql );
88+ $ this ->rt = $ this ->query ->execute ($ data );
89+ if ($ this ->rt ) {
90+ //return $this->connection->lastInsertId();
91+ return $ this ->rt ;
92+ }
93+
94+
95+ // TODO: Implement Insert() method.
96+ }
97+
98+ public function Update ($ table , $ id = array (), $ data = array ())
99+ {
100+
101+ $ quete = "" ;
102+
103+ foreach ($ data as $ x => $ val ) {
104+ $ quete .= "$ x = ' $ val', " ;
105+ }
106+
107+ $ res = rtrim ($ quete ,", " );
108+
109+ $ wher = "" ;
110+
111+ foreach ($ id as $ x => $ val ) {
112+ $ wher .= "$ x = $ val, " ;
113+ }
114+
115+ $ wh = rtrim ($ wher ,", " );
116+
117+
118+ $ this ->sql = "UPDATE " .$ table ." SET " . $ res . " WHERE " .$ wh ."; " ;
119+
120+ $ this ->query = $ this ->connetction ->prepare ($ this ->sql );
121+
122+ $ this ->rt = $ this ->query ->execute ();
123+ if ($ this ->rt ) {
124+ return $ this ->rt ;
125+
126+ }
127+
128+ }
129+
130+ public function Delete ($ table , $ id = array ())
131+ {
132+
133+ $ wher = "" ;
134+
135+ foreach ($ id as $ x => $ val ) {
136+ $ wher .= "$ x = $ val, " ;
137+ }
138+
139+ $ wh = rtrim ($ wher ,", " );
140+
141+ $ this ->sql = "DELETE FROM " .$ table ." WHERE " .$ wh ."; " ;
142+ $ this ->query = $ this ->connetction ->prepare ($ this ->sql );
143+ $ this ->rt = $ this ->query ->execute ();
144+ if ($ this ->rt ) {
145+ return $ this ->rt ;
146+
147+ }
148+ }
149+
150+
151+
152+
153+ }
154+
155+
156+
157+
158+ ?>
0 commit comments