@@ -153,6 +153,10 @@ function createTable ($name, $data) {
153153 exit ;
154154}
155155
156+ $ q = "drop table {$ prefix }test; " ;
157+ $ db ->rawQuery ($ q );
158+
159+
156160$ db ->orderBy ("id " ,"asc " );
157161$ users = $ db ->get ("users " );
158162if ($ db ->count != 3 ) {
@@ -253,22 +257,22 @@ function createTable ($name, $data) {
253257 echo "Invalid users count on where() with between " ;
254258 exit ;
255259}
256-
260+ ///
257261$ db ->where ("id " , 2 );
258262$ db ->orWhere ("customerId " , 11 );
259263$ r = $ db ->get ("users " );
260264if ($ db ->count != 2 ) {
261265 echo "Invalid users count on orWhere() " ;
262266 exit ;
263267}
264-
268+ ///
265269$ db ->where ("lastName " , NULL , '<=> ' );
266270$ r = $ db ->get ("users " );
267271if ($ db ->count != 1 ) {
268272 echo "Invalid users count on null where() " ;
269273 exit ;
270274}
271-
275+ ///
272276$ db ->join ("users u " , "p.userId=u.id " , "LEFT " );
273277$ db ->where ("u.login " ,'user2 ' );
274278$ db ->orderBy ("CONCAT(u.login, u.firstName) " );
@@ -277,34 +281,48 @@ function createTable ($name, $data) {
277281 echo "Invalid products count on join () " ;
278282 exit ;
279283}
280-
284+ ///
281285$ db ->where ("id = ? or id = ? " , Array (1 ,2 ));
282286$ res = $ db ->get ("users " );
283287if ($ db ->count != 2 ) {
284288 echo "Invalid users count on select with multiple params " ;
285289 exit ;
286290}
287291
292+ ///
288293$ db ->where ("id = 1 or id = 2 " );
289294$ res = $ db ->get ("users " );
290295if ($ db ->count != 2 ) {
291296 echo "Invalid users count on select with multiple params " ;
292297 exit ;
293298}
294-
299+ ///
295300$ usersQ = $ db ->subQuery ();
296301$ usersQ ->where ("login " , "user2 " );
297302$ usersQ ->getOne ("users " , "id " );
298303
299- $ db2 = $ db ->copy ();
300- $ db2 ->where ("userId " , $ usersQ );
301- $ cnt = $ db2 ->getValue ("products " , "count(id) " );
304+ $ db ->where ("userId " , $ usersQ );
305+ $ cnt = $ db ->getValue ("products " , "count(id) " );
302306if ($ cnt != 2 ) {
303307 echo "Invalid select result with subquery " ;
304308 exit ;
305309}
306-
307-
310+ ///
311+ $ dbi_sub = $ db ->subQuery ();
312+ $ dbi_sub ->where ('active ' , 1 );
313+ $ dbi_sub ->get ('users ' , null , 'id ' );
314+
315+ $ db ->where ('id ' , $ dbi_sub , 'IN ' );
316+
317+ $ cnt = $ db ->copy ();
318+ $ count_members = $ cnt ->getValue ('users ' , "COUNT(id) " );
319+ echo "count {$ count_members }\n" ;
320+ echo $ cnt ->getLastQuery () . "\n" ;
321+
322+ $ data = $ db ->get ('users ' );
323+ print_r ($ data );
324+ echo $ cnt ->getLastQuery () . "\n" ;
325+ ///
308326$ usersQ = $ db ->subQuery ("u " );
309327$ usersQ ->where ("active " , 1 );
310328$ usersQ ->get ("users " );
@@ -319,7 +337,7 @@ function createTable ($name, $data) {
319337 echo "invalid join with subquery count " ;
320338 exit ;
321339}
322-
340+ ///
323341//TODO: insert test
324342$ db ->delete ("users " );
325343$ db ->get ("users " );
@@ -329,9 +347,6 @@ function createTable ($name, $data) {
329347}
330348$ db ->delete ("products " );
331349
332- $ q = "drop table {$ prefix }test; " ;
333- $ db ->rawQuery ($ q );
334-
335350echo "All done " ;
336351
337352//print_r($db->rawQuery("CALL simpleproc(?)",Array("test")));
0 commit comments