-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathewmysql7.php
1093 lines (991 loc) · 24.1 KB
/
ewmysql7.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* MySQL API for PHPMaker 7
* (C) 2002-2010 e.World Technology Limited
*
* This script (ewmysql*.php) is based on:
* V1.42 ADOdb Lite 11 January 2007 (C) 2005-2007 Mark Dickenson. Released LGPL.
*/
$PHPMaker_vers = 'PHPMaker 7 (C) 2002-2010 e.World Technology Limited';
define('ADODB_FETCH_DEFAULT', 0);
define('ADODB_FETCH_NUM', 1);
define('ADODB_FETCH_ASSOC', 2);
define('ADODB_FETCH_BOTH', 3);
define('EW_USE_MYSQLI', FALSE && extension_loaded("mysqli"), TRUE);
/**
* ADOConnection
*/
class ADOConnection
{
var $connectionId = false;
var $record_set = false;
var $database;
var $dbtype;
var $dataProvider;
var $host;
var $open;
var $password;
var $username;
var $persistent;
var $debug = false;
var $debug_console = false;
var $debug_echo = true;
var $debug_output;
var $forcenewconnection = false;
var $createdatabase = false;
var $last_module_name;
var $socket = false;
var $port = false;
var $clientFlags = 0;
var $nameQuote = '"';
var $sysDate = false; /// name of function that returns the current date
var $sysTimeStamp = false; /// name of function that returns the current timestamp
var $sql;
var $raiseErrorFn = false;
var $query_count = 0;
var $query_time_total = 0;
var $query_list = array();
var $query_list_time = array();
var $query_list_errors = array();
var $_logsql = false;
function ADOConnection()
{
}
/**
* Returns floating point version number of PHPMaker
* Usage: $db->Version();
*
* @access public
*/
function Version()
{
global $PHPMaker_vers;
return (float) substr($PHPMaker_vers,1);
}
/**
* Returns true if connected to database
* Usage: $db->IsConnected();
*
* @access public
*/
function IsConnected()
{
if($this->connectionId === false || $this->connectionId == false)
return false;
else return true;
}
/**
* Normal Database connection
* Usage: $result = $db->Connect('host', 'username', 'password', 'database');
*
* @access public
* @param string $database
* @param string $host
* @param string $password
* @param string $username
* @param string $forcenew // private
*/
function Connect( $host = "", $username = "", $password = "", $database = "", $forcenew = false)
{
return $this->_connect($host, $username, $password, $database, false, $forcenew);
}
/**
* Persistent Database connection
* Usage: $result = $db->PConnect('host', 'username', 'password', 'database');
*
* @access public
* @param string $database
* @param string $host
* @param string $password
* @param string $username
*/
function PConnect( $host = "", $username = "", $password = "", $database = "")
{
return $this->_connect($host, $username, $password, $database, true, false);
}
/**
* Force New Database connection
* Usage: $result = $db->NConnect('host', 'username', 'password', 'database');
*
* @access public
* @param string $database
* @param string $host
* @param string $password
* @param string $username
*/
function NConnect( $host = "", $username = "", $password = "", $database = "")
{
return $this->_connect($host, $username, $password, $database, false, true);
}
/**
* Returns SQL query and instantiates sql statement & resultset driver
* Usage: $linkId =& $db->execute( 'SELECT * FROM foo ORDER BY id' );
*
* @access public
* @param string $sql
* @return mixed Resource ID, Array
*/
function &Execute( $sql, $inputarr = false )
{
// adodb_log_sql will time the query execution and log the sql query
// note: the later $this->do_query() should not run since adodb_log_sql() independently executes the query itself.
if($this->_logsql === true)
{
$ret =& adodb_log_sql($this, $sql, $inputarr);
if (isset($ret)) return $ret;
}
$rs =& $this->do_query($sql, -1, -1, $inputarr);
return $rs;
}
/**
* Returns SQL query and instantiates sql statement & resultset driver
* Usage: $linkId =& $db->SelectLimit( 'SELECT * FROM foo ORDER BY id', $nrows, $offset );
* $nrows and $offset are optional
*
* @access public
* @param string $sql
* @param string $nrows
* @param string $offset
* @return mixed Resource ID, Array
*/
function &SelectLimit( $sql, $nrows=-1, $offset=-1, $inputarr=false, $secs2cache=0 )
{
$rs =& $this->do_query( $sql, $offset, $nrows, $inputarr);
return $rs;
}
/**
* Display debug output and database error.
*
* @access private
*/
function outp($text, $newline = true)
{
global $ADODB_OUTP;
$this->debug_output = "<br>\n(" . $this->dbtype . "): ".htmlspecialchars($text)."<br>\n Error (" . $this->ErrorNo() .'): '. $this->ErrorMsg() . "<br>\n";
if(defined('ADODB_OUTP'))
{
$fn = ADODB_OUTP;
} else if(isset($ADODB_OUTP))
{
$fn = $ADODB_OUTP;
}
if(defined('ADODB_OUTP') || isset($ADODB_OUTP))
{
$fn($this->debug_output, $newline);
return;
}
if($this->debug_echo)
echo $this->debug_output;
}
}
/**
* Empty result record set for updates, inserts, ect
*
* @access private
*/
class ADORecordSet_empty
{
var $fields = false;
var $EOF = true;
function MoveNext() {return;}
function RecordCount() {return 0;}
function FieldCount() {return 0;}
function EOF(){return TRUE;}
function Close(){return true;}
}
/**
* mysqlt_driver_ADOConnection
*/
class mysqlt_driver_ADOConnection extends ADOConnection
{
var $autoCommit = true;
var $transOff = 0;
var $transCnt = 0;
var $transaction_status = true;
var $nameQuote = '`';
var $sysDate = 'CURDATE()';
var $sysTimeStamp = 'NOW()';
var $isoDates = true; // accepts dates in ISO format
function mysqlt_driver_ADOConnection()
{
$this->dbtype = 'mysqlt';
$this->dataProvider = 'mysql';
$this->last_module_name = 'mysqlt_driver';
}
/**
* Connection to database server and selected database
*
* @access private
*/
function _connect($host = "", $username = "", $password = "", $database = "", $persistent, $forcenew)
{
if (EW_USE_MYSQLI) {
if (!function_exists('mysqli_real_connect')) return false;
$this->host = $host;
$this->username = $username;
$this->password = $password;
$this->database = $database;
$this->persistent = $persistent;
$this->forcenewconnection = $forcenew;
$this->connectionId = @mysqli_init();
@mysqli_real_connect( $this->connectionId, $this->host, $this->username, $this->password, $this->database, $this->port, $this->socket, $this->clientFlags );
if (mysqli_connect_errno() != 0)
{
$this->connectionId = false;
}
} else {
if (!function_exists('mysql_connect')) return false;
$this->host = $host;
if (!empty($this->port)) $this->host .= ":" . $this->port;
$this->username = $username;
$this->password = $password;
$this->database = $database;
$this->persistent = $persistent;
$this->forcenewconnection = $forcenew;
if($this->persistent == 1)
{
if (strnatcmp(PHP_VERSION, '4.3.0') >= 0)
$this->connectionId = @mysql_pconnect( $this->host, $this->username, $this->password, $this->clientFlags );
else
$this->connectionId = @mysql_pconnect( $this->host, $this->username, $this->password );
}
else
{
if (strnatcmp(PHP_VERSION, '4.3.0') >= 0)
$this->connectionId = @mysql_connect( $this->host, $this->username, $this->password, $this->forcenewconnection, $this->clientFlags );
else if (strnatcmp(PHP_VERSION, '4.2.0') >= 0)
$this->connectionId = @mysql_connect( $this->host, $this->username, $this->password, $this->forcenewconnection );
else
$this->connectionId = @mysql_connect( $this->host, $this->username, $this->password );
}
}
if ($this->connectionId === false)
{
if ($fn = $this->raiseErrorFn)
$fn($this->dbtype, 'CONNECT', $this->ErrorNo(), $this->ErrorMsg(), $this->host, $this->database, $this);
return false;
}
if (!empty($this->database))
{
if($this->SelectDB( $this->database ) == false)
{
$this->connectionId = false;
return false;
}
}
return true;
}
/**
* Choose a database to connect.
*
* @param dbname is the name of the database to select
* @return true or false
* @access public
*/
function SelectDB($dbname)
{
$this->database = $dbname;
if ($this->connectionId === false)
{
$this->connectionId = false;
return false;
}
else
{
if (EW_USE_MYSQLI) {
$result = @mysqli_select_db( $this->connectionId, $this->database );
} else {
$result = @mysql_select_db( $this->database, $this->connectionId );
}
if($result === false)
{
if($this->createdatabase == true)
{
if (EW_USE_MYSQLI) {
$result = @mysqli_query( $this->connectionId, "CREATE DATABASE IF NOT EXISTS " . $this->database );
} else {
$result = @mysql_query( "CREATE DATABASE IF NOT EXISTS " . $this->database, $this->connectionId );
}
if ($result === false) { // error handling if query fails
return false;
}
if (EW_USE_MYSQLI) {
$result = @mysqli_select_db( $this->connectionId, $this->database );
} else {
$result = @mysql_select_db( $this->database, $this->connectionId );
}
if($result === false)
{
return false;
}
}
else
{
return false;
}
}
return true;
}
}
/**
* Return database error message
* Usage: $errormessage =& $db->ErrorMsg();
*
* @access public
*/
function ErrorMsg()
{
if ($this->connectionId === false)
{
if (EW_USE_MYSQLI) {
return @mysqli_connect_error();
} else {
return @mysql_error();
}
}
else
{
if (EW_USE_MYSQLI) {
return @mysqli_error($this->connectionId);
} else {
return @mysql_error($this->connectionId);
}
}
}
/**
* Return database error number
* Usage: $errorbo =& $db->ErrorNo();
*
* @access public
*/
function ErrorNo()
{
if ($this->connectionId === false)
{
if (EW_USE_MYSQLI) {
return @mysqli_connect_errno();
} else {
return @mysql_errno();
}
}
else
{
if (EW_USE_MYSQLI) {
return @mysqli_errno($this->connectionId);
} else {
return @mysql_errno($this->connectionId);
}
}
}
/**
* Returns # of affected rows from insert/delete/update query
*
* @access public
* @return integer Affected rows
*/
function Affected_Rows()
{
if (EW_USE_MYSQLI) {
return @mysqli_affected_rows($this->connectionId);
} else {
return @mysql_affected_rows($this->connectionId);
}
}
/**
* Returns the last record id of an inserted item
* Usage: $db->Insert_ID();
*
* @access public
*/
function Insert_ID()
{
if (EW_USE_MYSQLI) {
return @mysqli_insert_id($this->connectionId);
} else {
return @mysql_insert_id($this->connectionId);
}
}
/**
* Correctly quotes a string so that all strings are escape coded.
* An example is $db->qstr("Haven't a clue.");
*
* @param string the string to quote
* @param [magic_quotes] if $s is GET/POST var, set to get_magic_quotes_gpc().
*
* @return single-quoted string IE: 'Haven\'t a clue.'
*/
function qstr($string, $magic_quotes=false)
{
if (!$magic_quotes) {
if (EW_USE_MYSQLI) {
if (strnatcmp(PHP_VERSION, '4.3.0') >= 0 && function_exists('mysqli_real_escape_string')) {
return "'" . mysqli_real_escape_string($this->connectionId, $string) . "'";
}
} else {
if (strnatcmp(PHP_VERSION, '4.3.0') >= 0) {
return "'" . mysql_real_escape_string($string, $this->connectionId) . "'";
}
}
$string = str_replace("'", "\\'" , str_replace('\\', '\\\\', str_replace("\0", "\\\0", $string)));
return "'" . $string . "'";
}
return "'" . str_replace('\\"', '"', $string) . "'";
}
function QMagic($string)
{
return $this->qstr($string, get_magic_quotes_gpc());
}
/**
* Returns concatenated string
* Usage: $db->Concat($str1,$str2);
*
* @return concatenated string
*/
function Concat()
{
$arr = func_get_args();
$list = implode(', ', $arr);
if (strlen($list) > 0) return "CONCAT($list)";
else return '';
}
function IfNull( $field, $ifNull )
{
return " IFNULL($field, $ifNull) ";
}
/**
* Closes database connection
* Usage: $db->close();
*
* @access public
*/
function Close()
{
if (EW_USE_MYSQLI) {
@mysqli_close( $this->connectionId );
} else {
@mysql_close( $this->connectionId );
}
$this->connectionId = false;
}
function StartTrans($errfn = 'ADODB_TransMonitor')
{
if ($this->transOff > 0) {
$this->transOff += 1;
return;
}
$this->transaction_status = true;
if ($this->debug && $this->transCnt > 0)
ADOConnection::outp("Bad Transaction: StartTrans called within BeginTrans");
$this->BeginTrans();
$this->transOff = 1;
}
function BeginTrans()
{
if ($this->transOff)
return true;
$this->transCnt += 1;
$this->Execute('SET AUTOCOMMIT=0');
$this->Execute('BEGIN');
return true;
}
function CompleteTrans($autoComplete = true)
{
if ($this->transOff > 1) {
$this->transOff -= 1;
return true;
}
$this->transOff = 0;
if ($this->transaction_status && $autoComplete) {
if (!$this->CommitTrans()) {
$this->transaction_status = false;
if ($this->debug)
ADOConnection::outp("Smart Commit failed");
} else
if ($this->debug)
ADOConnection::outp("Smart Commit occurred");
} else {
$this->RollbackTrans();
if ($this->debug)
ADOCOnnection::outp("Smart Rollback occurred");
}
return $this->transaction_status;
}
function CommitTrans($ok=true)
{
if ($this->transOff)
return true;
if (!$ok) return
$this->RollbackTrans();
if ($this->transCnt)
$this->transCnt -= 1;
$this->Execute('COMMIT');
$this->Execute('SET AUTOCOMMIT=1');
return true;
}
function RollbackTrans()
{
if ($this->transOff)
return true;
if ($this->transCnt)
$this->transCnt -= 1;
$this->Execute('ROLLBACK');
$this->Execute('SET AUTOCOMMIT=1');
return true;
}
function FailTrans()
{
if ($this->debug)
if ($this->transOff == 0) {
ADOConnection::outp("FailTrans outside StartTrans/CompleteTrans");
} else {
ADOConnection::outp("FailTrans was called");
}
$this->transaction_status = false;
}
function HasFailedTrans()
{
if ($this->transOff > 0)
return $this->transaction_status == false;
return false;
}
function RowLock($tables,$where,$flds='1 as ignore')
{
if ($this->transCnt==0)
$this->BeginTrans();
return $this->GetOne("select $flds from $tables where $where for update");
}
function CommitLock($table)
{
return $this->CommitTrans();
}
function RollbackLock($table)
{
return $this->RollbackTrans();
}
/**
* Returns All Records in an array
*
* Usage: $db->GetAll($sql);
* @access public
*/
function &GetAll($sql, $inputarr = false)
{
$data =& $this->GetArray($sql, $inputarr);
return $data;
}
/**
* Returns All Records in an array
*
* Usage: $db->GetArray($sql);
* @access public
*/
function &GetArray($sql, $inputarr = false)
{
$data = false;
$result =& $this->Execute($sql, $inputarr);
if ($result)
{
$data =& $result->GetArray();
$result->Close();
}
return $data;
}
/**
* Return first element of first row of sql statement. Recordset is disposed
* for you.
*
* @param sql SQL statement
* @param [inputarr] input bind array
*/
function GetOne($sql, $inputarr = false)
{
$ret = false;
$rs =& $this->Execute($sql, $inputarr);
if ($rs) {
if (!$rs->EOF) $ret = reset($rs->fields);
$rs->Close();
}
return $ret;
}
/**
* Executes SQL query and instantiates resultset methods
*
* @access private
* @return mixed Resultset methods
*/
function &do_query( $sql, $offset, $nrows, $inputarr=false )
{
global $ADODB_FETCH_MODE;
$false = false;
$limit = '';
if ($offset >= 0 || $nrows >= 0)
{
$offset = ($offset >= 0) ? $offset . "," : '';
$nrows = ($nrows >= 0) ? $nrows : '18446744073709551615';
$limit = ' LIMIT ' . $offset . ' ' . $nrows;
}
if ($inputarr && is_array($inputarr)) {
$sqlarr = explode('?', $sql);
if (!is_array(reset($inputarr))) $inputarr = array($inputarr);
foreach($inputarr as $arr) {
$sql = ''; $i = 0;
foreach($arr as $v) {
$sql .= $sqlarr[$i];
switch(gettype($v)){
case 'string':
$sql .= $this->qstr($v);
break;
case 'double':
$sql .= str_replace(',', '.', $v);
break;
case 'boolean':
$sql .= $v ? 1 : 0;
break;
default:
if ($v === null)
$sql .= 'NULL';
else $sql .= $v;
}
$i += 1;
}
$sql .= $sqlarr[$i];
if ($i+1 != sizeof($sqlarr))
return $false;
$this->sql = $sql . $limit;
$time_start = array_sum(explode(' ', microtime()));
$this->query_count++;
if (EW_USE_MYSQLI) {
$resultId = @mysqli_query($this->connectionId, $this->sql );
} else {
$resultId = @mysql_query( $this->sql, $this->connectionId );
}
$time_total = (array_sum(explode(' ', microtime())) - $time_start);
$this->query_time_total += $time_total;
if($this->debug_console)
{
$this->query_list[] = $this->sql;
$this->query_list_time[] = $time_total;
$this->query_list_errors[] = $this->ErrorMsg();
}
if($this->debug)
{
$this->outp($sql . $limit);
}
}
}
else
{
$this->sql = $sql . $limit;
$time_start = array_sum(explode(' ', microtime()));
$this->query_count++;
if (EW_USE_MYSQLI) {
$resultId = @mysqli_query($this->connectionId, $this->sql );
} else {
$resultId = @mysql_query( $this->sql, $this->connectionId );
}
$time_total = (array_sum(explode(' ', microtime())) - $time_start);
$this->query_time_total += $time_total;
if($this->debug_console)
{
$this->query_list[] = $this->sql;
$this->query_list_time[] = $time_total;
$this->query_list_errors[] = $this->ErrorMsg();
}
if($this->debug)
{
$this->outp($sql . $limit);
}
}
if ($resultId === false) { // error handling if query fails
if ($fn = $this->raiseErrorFn)
$fn($this->dbtype, 'EXECUTE', $this->ErrorNo(), $this->ErrorMsg(), $this->sql, $inputarr, $this);
return $false;
}
if ($resultId === true) { // return simplified recordset for inserts/updates/deletes with lower overhead
$recordset = new ADORecordSet_empty();
return $recordset;
}
$resultset_name = $this->last_module_name . "_ResultSet";
$recordset = new $resultset_name( $resultId, $this->connectionId );
$recordset->_currentRow = 0;
if (EW_USE_MYSQLI) {
switch ($ADODB_FETCH_MODE)
{
case ADODB_FETCH_NUM: $recordset->fetchMode = MYSQLI_NUM; break;
case ADODB_FETCH_ASSOC:$recordset->fetchMode = MYSQLI_ASSOC; break;
default:
case ADODB_FETCH_DEFAULT:
case ADODB_FETCH_BOTH:$recordset->fetchMode = MYSQLI_BOTH; break;
}
} else {
switch ($ADODB_FETCH_MODE)
{
case ADODB_FETCH_NUM: $recordset->fetchMode = MYSQL_NUM; break;
case ADODB_FETCH_ASSOC:$recordset->fetchMode = MYSQL_ASSOC; break;
default:
case ADODB_FETCH_DEFAULT:
case ADODB_FETCH_BOTH:$recordset->fetchMode = MYSQL_BOTH; break;
}
}
if (EW_USE_MYSQLI) {
$recordset->_numOfRows = @mysqli_num_rows( $resultId );
} else {
$recordset->_numOfRows = @mysql_num_rows( $resultId );
}
if( $recordset->_numOfRows == 0)
{
$recordset->EOF = true;
}
if (EW_USE_MYSQLI) {
$recordset->_numOfFields = @mysqli_num_fields( $resultId );
} else {
$recordset->_numOfFields = @mysql_num_fields( $resultId );
}
$recordset->_fetch();
return $recordset;
}
}
class mysqlt_driver_ResultSet
{
var $connectionId;
var $fields;
var $resultId;
var $_currentRow = 0;
var $_numOfRows = -1;
var $_numOfFields = -1;
var $fetchMode;
var $EOF;
/**
* mysqlResultSet Constructor
*
* @access private
* @param string $record
* @param string $resultId
*/
function mysqlt_driver_ResultSet( $resultId, $connectionId )
{
$this->fields = array();
$this->connectionId = $connectionId;
$this->record = array();
$this->resultId = $resultId;
$this->EOF = false;
}
/**
* Frees resultset
*
* @access public
*/
function Close()
{
if (EW_USE_MYSQLI) {
@mysqli_free_result( $this->resultId );
} else {
@mysql_free_result( $this->resultId );
}
$this->fields = array();
$this->resultId = false;
}
/**
* Returns field name from select query
*
* @access public
* @param string $field
* @return string Field name
*/
function fields( $field )
{
if(empty($field))
{
return $this->fields;
}
else
{
return $this->fields[$field];
}
}
/**
* Returns numrows from select query
*
* @access public
* @return integer Numrows
*/
function RecordCount()
{
return $this->_numOfRows;
}
/**
* Returns num of fields from select query
*
* @access public
* @return integer numfields
*/
function FieldCount()
{
return $this->_numOfFields;
}
/**
* Returns next record
*
* @access public
*/
function MoveNext()
{
if (EW_USE_MYSQLI) {
$this->fields = @mysqli_fetch_array($this->resultId,$this->fetchMode);
} else {
$this->fields = @mysql_fetch_array($this->resultId, $this->fetchMode);
}
if ($this->fields) {
$this->_currentRow += 1;
return true;
}
if (!$this->EOF) {
$this->_currentRow += 1;
$this->EOF = true;
}
return false;
}
/**
* Move to the first row in the recordset. Many databases do NOT support this.
*
* @return true or false
*/
function MoveFirst()
{
if ($this->_currentRow == 0) return true;
return $this->Move(0);
}
/**
* Returns the Last Record
*
* @access public
*/
function MoveLast()
{
if ($this->EOF) return false;
return $this->Move($this->_numOfRows - 1);
}
/**
* Random access to a specific row in the recordset. Some databases do not support
* access to previous rows in the databases (no scrolling backwards).
*
* @param rowNumber is the row to move to (0-based)
*
* @return true if there still rows available, or false if there are no more rows (EOF).
*/
function Move($rowNumber = 0)
{
if ($rowNumber == $this->_currentRow) return true;
$this->EOF = false;
if ($this->_numOfRows > 0){
if ($rowNumber >= $this->_numOfRows - 1){
$rowNumber = $this->_numOfRows - 1;
}
}
if ($this->_seek($rowNumber)) {
$this->_currentRow = $rowNumber;
if ($this->_fetch()) {
return true;
}
$this->fields = false;
}
$this->EOF = true;
return false;
}
/**
* Perform Seek to specific row
*
* @access private
*/
function _seek($row)
{
if ($this->_numOfRows == 0) return false;
if (EW_USE_MYSQLI) {
return @mysqli_data_seek($this->resultId,$row);
} else {
return @mysql_data_seek($this->resultId,$row);
}
}