-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.inc
1395 lines (1260 loc) · 39.3 KB
/
database.inc
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
# ---------------------------------------------------------------------------------------
# Database Abstraction Layer
# Primary Class Author: Frank M. Kromman <[email protected]>
# Docs, MySQL Support, and Minor Class Modifications: Geoff A. Virgo <[email protected]>
# Release Date: November 11, 2001
# Licensing: Lesser GNU Public License (LGPL)
# ---------------------------------------------------------------------------------------
# Requirements:
#
# - PHP 4.0.0 or higher (may also work with PHP3) configured with smtp or
# sendmail support
# - a webserver configured to run PHP
#
# For installation and usage, read the README section in the API Docs.
#
/** The base class used to store database connection resource identifiers, number of columns
** and rows in a result set, available database objects, and provide error-handling via runtime
** debugging emails. The class is private and shouldn't be accessed directly.
** @author Frank M. Kromann <[email protected]>
** @author Geoff A. Virgo <[email protected]> - internal documentation and minor code revision
**/
class cDBConstruct {
/** This is an integer variable used to store the resource
** identifer for the current database connection.
** @type int
** @public
**/
var $conn;
/** This is an integer variable used to store the number
** of columns in the current result set.
** @type int
** @public
**/
var $columns;
/** This is an integer variable used to store the number
** of rows in the current result set.
** @type int
** @public
**/
var $rows;
/** This is an integer variable used to store the number
** of rows in the current result set.
** @type int
** @public
**/
var $row;
/** This is an integer variable used to store the current
** date at the time of instanciation.
** @type int
** @public
**/
var $currentDate;
/** This is an integer variable used to store the current
** system time at the time of instanciation.
** @type int
** @public
**/
var $currentTime;
/** This is a string variable used to store the address
** to which debugging emails are sent.
** @type string
** @public
**/
var $adminEmail;
/** This is a string variable used to store the name of the
** webserver or virtual host.
** @type string
** @private
**/
var $serverName;
/** This is a string variable used to store the name of
** the webserver software.
** @type string
** @private
**/
var $serverSoftware;
/** This is a string variable used to store the address
** which the webserver is running on.
** @type string
** @private
**/
var $serverAddress;
/** This is a string variable used to store the relative
** path and filename of the file calling this class.
** @type string
** @private
**/
var $currentScript;
/** The class constructor returns nothing, it merely sets the
** resource id, number of rows, number of columns, date,
** and time variables to their default state.
** @private
**/
function cDBConstruct()
{
global $HTTP_SERVER_VARS;
$this->conn = NULL;
$this->columns = NULL;
$this->rows = NULL;
$this->currentDate = date("Y-m-d");
$this->currentTime = date("H:i:s");
$this->row = 0;
$this->serverName = $HTTP_SERVER_VARS["SERVER_NAME"];
$this->serverSoftware = $HTTP_SERVER_VARS["SERVER_SOFTWARE"];
$this->currentScript = $HTTP_SERVER_VARS["PATH_TRANSLATED"];
$this->SetAdminEmail();
}
/** This function sets the email address used in the SQL debugging
** methods below.
** @returns void
** @public
**/
function SetAdminEmail($email="")
{
global $admin_email;
$email=="" ? $this->adminEmail = $admin_email : $this->adminEmail = $email;
return true;
}
/** The error handling function called in a die operation upon failure to
** create a connection to the specified server. Sends a brief email to a
** designated admin email account (specified in settings file as
** $admin_email) notifying of the failure.
** @returns void
** @private
**/
function _DBConnectionError()
{
global $HTTP_SERVER_VARS;
// create email body
$body = "On " . $this->currentDate . " at " . $this->currentTime . ", a user was unable to ";
$body .= "connect to the database server. The error occured in " . $this->currentScript . ".";
$HTTP_SERVER_VARS["SERVER_ADDR"] == "24.78.38.253" ? $send = TRUE : $send = FALSE;
if ($send)
$this->_sendMail($body);
else
echo nl2br($body) . "<br>";
return false;
}
/** The error handling function called in a die operation upon failure to
** create a select a database on the current connection. Sends a
** brief email to a designated admin email account (specified in settings file as
** $admin_email) notifying of the failure.
** @returns void
** @private
**/
function _DBSelectionError()
{
global $HTTP_SERVER_VARS;
// create email body
$body = "On " . $this->currentDate . " at " . $this->currentTime . ", a user connected to ";
$body .= "the database server but was unable to select the correct database. The error ";
$body .= "occured in " . $this->currentScript . ".";
$HTTP_SERVER_VARS["SERVER_ADDR"] == "24.78.38.253" ? $send = TRUE : $send = FALSE;
if ($send)
$this->_sendMail($body);
else
echo nl2br($body) . "<br>";
return false;
}
/** The error handling function called in a die operation upon failure to
** execute an SQL query. Sends a brief email to a designated admin
** email account (specified in settings file as $admin_email) notifying
** of the failure, detailing the file in which the failure occured, and providing
** the faulty query.
** @returns void
** @private
**/
function _SQLError($sql,$error)
{
global $HTTP_SERVER_VARS;
// create email body
$body = "On " . $this->currentDate . " at " . $this->currentTime . ", an sql error occured. ";
$body .= "When asked the trouble, the database said:\n\n\"".trim($error)."\"\n\n";
$body .= "The error was thrown from " . $this->currentScript . " in the function $type and ";
$body .= "the offending sql statement is below:\n\n\n$sql";
$HTTP_SERVER_VARS["SERVER_ADDR"] == "24.78.38.253" ? $send = TRUE : $send = FALSE;
if ($send)
$this->_sendMail($body);
else
echo nl2br($body) . "<br>";
return false;
}
/** The function used to send sql error report emails.
** @returns void
** @private
**/
function _sendMail($body,$to="",$subject="",$headers="",$cc="",$bcc="",$html=false)
{
global $HTTP_SERVER_VARS;
if ($headers == "") {
$headers = "From: \"Automated Script Debugger System at " . $this->serverName . "\"\nReply-To: ";
$headers .= "\"Automated Script Debugger System at " . $this->serverName . "\"\nX-Mailer: \"";
$headers .= $this->serverName . " via " . $this->serverSoftware . "\"";
}
if ($subject == "")
$subject = "Script Error";
if ($html)
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
if ($cc != "")
$headers .= $cc;
if ($bcc != "")
$headers .= $bcc;
$to == "" ? $to = $this->adminEmail : TRUE;
$HTTP_SERVER_VARS["SERVER_ADDR"] == "127.0.0.1" ? $send = FALSE : $send = TRUE;
if ($send)
@mail($to, $subject, $body, $headers);
else
echo nl2br($body) . "<br>";
}
}
/** A class used to wrap PHP's FrontBase connectivity functions. While it can be
** accessed directly, the recommended method is to access it through the wrapper
** Databases() class.
** @author Frank M. Kromann <[email protected]>
** @author Geoff A. Virgo <[email protected]> - internal documentation
**/
class cFrontBase extends cDBConstruct {
/** The class constructor undertakes no actions beyond returning boolean true.
** It is included merely for good style and against the needs of future expansion.
**/
function cFrontBase()
{
$this->cDBConstruct();
return true;
}
/** This method is used to connect to the specified FrontBase server. All accepted
** arguments are strings, with $strDatabase being optional. If $strDatabase is specified
** the method will try to select that database.
** @returns void
** @public
**/
function Connect($strHost, $strUser, $strPassword, $strDatabase)
{
$this->conn = @fbsql_pconnect($strHost, $strUser, $strPassword) or $this->_DBConnectionError();
if (!@fbsql_select_db($strDatabase, $this->conn)) {
$this->Disconnect();
$this->_DBSelectionError();
}
$this->columns = 0;
$this->rows = 0;
}
/** Used to disconnect from the current FrontBase database connection.
** @returns void
** @public
**/
function Disconnect()
{
@fbsql_close($this->conn);
$this->conn = null;
}
/** Used to execute SQL queries on the currently opened database connection.
** Updates the $columns and $rows variables from the cDBConstruct() class
** with the values specific to the passed query. Returns a resource identifier
** on success or false on failure.
** @returns int
** @public
**/
function Query($strSQL)
{
$this->columns = 0;
$this->rows = 0;
$rs = @fbsql_query("$strSQL;", $this->conn) or $this->_SQLError($strSQL,$this->GetLastMessage());
if ($rs > 0) {
$this->columns = @fbsql_num_fields($rs);
$this->rows = @fbsql_num_rows($rs);
}
return $rs;
}
/** Used to get the name of the column specified by $col in the result set identifed by $rs.
** Returns a string containing the column's name on success an null on failure.
** @returns string
** @public
**/
function ColumnName($rs, $col)
{
if ($rs) return @fbsql_field_name($rs, $col);
}
/** Used to get the maximum length that column, $col, from result, $rs,
** can contain. Returns the maximum length as an integer on success and
** null on failure.
** @returns int
** @public
**/
function ColumnLength($rs, $col)
{
if ($rs) return @fbsql_field_len($rs, $col);
}
/** Used to get the datatype of the column, $col, from result set, $rs, can contain.
** Returns a the datatype as a string on success and null on error.
** @returns string
** @public
**/
function ColumnType($rs, $col)
{
if ($rs) return @fbsql_field_type($rs, $col);
}
/** Used to read the current returned row from result result, $rs, into a numerically
** indexed array. Returns an array containing the row's values indexed by column
** number or success, or false if no further rows exist in the result set.
** can contain.
** @returns array
** @public
**/
function FetchRow($rs,$type=2)
{
if (is_resource($rs)) return @fbsql_fetch_array($rs,$type);
}
/** Used to get and return the number of rows in the current result set
** can contain.
** @returns int
** @public
**/
function NumRows($rs)
{
if (is_resource($rs)) return @fbsql_num_rows($rs);
}
/** Used to switch to the next result set in the case of multiple
** record sets being returned from a stored procedure. Returns
** true if another result set exists, false if not further result sets
** are found. Updates the $columns and $rows variables from
** the cDBConstruct() class with the new result set's values.
** @returns boolean
** @public
**/
function NextResult($rs)
{
$ret = false;
if ($rs > 0) {
if (@fbsql_next_result($rs)) {
$this->columns = @fbsql_num_fields($rs);
$this->rows = @fbsql_num_rows($rs);
$ret = true;
}
else {
$this->columns = 0;
$this->rows = 0;
$ret = false;
}
}
return $ret;
}
/** Used to free the current result set, $rs, from memory.
** @returns void
** @public
**/
function FreeResult($rs)
{
if ($rs > 0) @fbsql_free_result($rs);
}
/** Used to get the text of the most recent error message on the
** current database connection. Returns the most recent error message
** as a string if such a message exists. Otherwise it returns boolean false.
** @returns string
** @public
**/
function GetLastMessage()
{
if ($this->conn) {
$strError = @fbsql_error($this->conn);
if ($strError)
return str_replace("\r\n", "\r", $strError);
else
return false;
}
else
return false;
}
}
/** A class used to wrap PHP's PostgreSQL connectivity functions. While it can be
** accessed directly, the recommended method is to access it through the wrapper
** cDatabases() class.
** @author Geoff A. Virgo <[email protected]>
**/
class cPostgreSQL extends cDBConstruct {
/** The class constructor undertakes no actions beyond returning boolean true.
** It is included merely for good style and against the needs of future expansion.
**/
function cPostgreSQL()
{
$this->cDBConstruct();
return true;
}
/** This method is used to connect to the specified FrontBase server. All accepted
** arguments are strings, with $strDatabase being optional. If $strDatabase is specified
** the method will try to select that database.
** @returns void
** @public
**/
function Connect($strHost, $strUser, $strPassword, $strDatabase)
{
$this->conn = @pg_pconnect("host=$strHost user=$strUser password=$strPassword dbname=$strDatabase") or $this->_DBConnectionError();
$this->columns = 0;
$this->rows = 0;
}
/** Used to disconnect from the current FrontBase database connection.
** @returns void
** @public
**/
function Disconnect()
{
@pg_close($this->conn);
$this->conn = null;
}
/** Used to execute SQL queries on the currently opened database connection.
** Updates the $columns and $rows variables from the cDBConstruct() class
** with the values specific to the passed query. Returns a resource identifier
** on success or false on failure.
** @returns int
** @public
**/
function Query($strSQL)
{
$this->columns = 0;
$this->rows = 0;
$this->row = 0;
$rs = @pg_exec($this->conn, $strSQL) or $this->_SQLError($strSQL,$this->GetLastMessage());
if ($rs > 0) {
$this->columns = @pg_numfields($rs);
$this->rows = @pg_numrows($rs);
}
return $rs;
}
/** Used to get the name of the column specified by $col in the result set identifed by $rs.
** Returns a string containing the column's name on success an null on failure.
** @returns string
** @public
**/
function ColumnName($rs, $col)
{
if ($rs) return @pg_fieldname($rs, $col);
}
/** Used to get the maximum length that column, $col, from result, $rs,
** can contain. Returns the maximum length as an integer on success and
** null on failure.
** @returns int
** @public
**/
function ColumnLength($rs, $col)
{
if ($rs) return @pg_fieldsize($rs, $col);
}
/** Used to get the datatype of the column, $col, from result set, $rs, can contain.
** Returns a the datatype as a string on success and null on error.
** @returns string
** @public
**/
function ColumnType($rs, $col)
{
if ($rs) return @pg_fieldname($rs, $col);
}
/** Used to read the current returned row from result result, $rs, into a numerically
** indexed array. Returns an array containing the row's values indexed by column
** number or success, or false if no further rows exist in the result set.
** can contain.
** @returns array
** @public
**/
function FetchRow($rs, $type=2)
{
if (is_resource($rs) && $this->row < $this->NumRows($rs)) {
$num = $this->row;
$this->row = ($num + 1);
return pg_fetch_array($rs,$num,$type);
}
}
/** Used to get and return the number of rows in the current result set
** can contain.
** @returns int
** @public
**/
function NumRows($rs)
{
if (is_resource($rs)) return @pg_numrows($rs);
}
/** This feature is currently not supported by PostgreSQL and exists merely for consistency
** within the abstraction layer. It should be consider deprecated.
** @returns boolean
** @deprecated
** @private
**/
function NextResult($rs)
{
/*
$ret = false;
if ($rs > 0) {
if (@fbsql_next_result($rs)) {
$this->columns = @fbsql_num_fields($rs);
$this->rows = @fbsql_num_rows($rs);
$ret = true;
}
else {
$this->columns = 0;
$this->rows = 0;
$ret = false;
}
}
return $ret;
*/
return true;
}
/** Used to free the current result set, $rs, from memory.
** @returns void
** @public
**/
function FreeResult($rs)
{
if ($rs > 0) @pg_freeresult($rs);
}
/** Used to get the text of the most recent error message on the
** current database connection. Returns the most recent error message
** as a string if such a message exists. Otherwise it returns boolean false.
** @returns string
** @public
**/
function GetLastMessage()
{
if ($this->conn) {
$strError = @pg_errormessage($this->conn);
if ($strError)
return str_replace("\r\n", "\r", $strError);
else
return false;
}
else
return false;
}
}
/** A class used to wrap PHP's MS-SQL Server connectivity functions. While it can be
** accessed directly, the recommended method is to access it through the wrapper
** cDatabases() class.
** @author Frank M. Kromann <[email protected]>
** @author Geoff A. Virgo <[email protected]> - internal documentation
**/
class cMSSQL extends cDBConstruct {
/** The class constructor undertakes no actions beyond returning boolean true.
** It is included merely for good style and against the needs of future expansion.
**/
function cMSSQL()
{
$this->cDBConstruct();
return true;
}
/** This method is used to connect to the specified MS SQL server. All accepted
** arguments are strings, with $strDatabase being optional. If $strDatabase is specified
** the method will try to select that database.
** @returns void
** @public
**/
function Connect($strHost, $strUser, $strPassword, $strDatabase)
{
$this->conn = @mssql_connect($strHost, $strUser, $strPassword) or $this->_DBConnectionError();
if ($this->conn) {
@mssql_select_db($strDatabase, $this->conn) or $this->_DBSelectionError();
}
@mssql_min_error_severity(100);
@mssql_min_message_severity(100);
$this->columns = 0;
$this->rows = 0;
}
/** Used to disconnect from the current FrontBase database connection.
** @returns void
** @public
**/
function Disconnect()
{
@mssql_close($this->conn);
$this->conn = null;
}
/** Used to execute SQL queries on the currently opened database connection.
** Updates the $columns and $rows variables from the cDBConstruct() class
** with the values specific to the passed query. Returns a resource identifier
** on success or false on failure.
** @returns int
** @public
**/
function Query($strSQL)
{
$this->columns = 0;
$this->rows = 0;
$rs = @mssql_query($strSQL, $this->conn) or $this->_SQLError($strSQL,$this->GetLastMessage());
if (is_resource($rs)) {
$this->columns = @mssql_num_fields($rs);
$this->rows = @mssql_num_rows($rs);
}
return $rs;
}
/** Used to get the name of the column specified by $col in the result set identifed by $rs
** Returns a string containing the column's name on success an null on failure.
** @returns string
** @public
**/
function ColumnName($rs, $col)
{
if ($rs) return @mssql_field_name($rs, $col);
}
/** Used to get the maximum length that column, $col, from result, $rs,
** can contain. Returns the maximum length as an integer on success and
** null on failure.
** @returns int
** @public
**/
function ColumnLength($rs, $col)
{
if ($rs) return @mssql_field_length($rs, $col);
}
/** Used to get the datatype of the column, $col, from result set, $rs, can contain.
** Returns a the datatype as a string on success and null on error.
** @returns string
** @public
**/
function ColumnType($rs, $col)
{
if ($rs) return @mssql_field_type($rs, $col);
}
/** Used to read the current returned row from result result, $rs, into a numerically
** indexed array. Returns an array containing the row's values indexed by column
** number or success, or false if no further rows exist in the result set.
** @returns array
** @public
**/
function FetchRow($rs,$type=2)
{
if (is_resource($rs)) {
if ($result = @mssql_fetch_row($rs)) {
$rowData = array();
for ($i = 0; $i < $this->columns; $i++) {
if ($type==1) {
return $result;
}
else if ($type==3) {
$rowData[] = $result[$i];
$rowData[@mssql_field_name($rs, $i)] = $result[$i];
}
else {
$rowData[@mssql_field_name($rs, $i)] = $result[$i];
}
}
}
}
unset($result);
return $rowData;
}
/** Used to get and return the number of rows in the current result set
** can contain.
** @returns int
** @public
**/
function NumRows($rs)
{
if (is_resource($rs)) return @mssql_num_rows($rs);
}
/** Used to switch to the next result set in the case of multiple
** record sets being returned from a stored procedure. Returns
** true if another result set exists, false if not further result sets
** are found. Updates the $columns and $rows variables from
** the cDBConstruct() class with the new result set's values.
** @returns boolean
** @public
**/
function NextResult($rs)
{
$ret = false;
if (is_resource($rs)) {
if (@mssql_next_result($rs)) {
$this->columns = @mssql_num_fields($rs);
$this->rows = @mssql_num_rows($rs);
$ret = true;
}
else {
$this->columns = 0;
$this->rows = 0;
$ret = false;
}
}
return $ret;
}
/** Used to free the current result set, $rs, from memory.
** @returns void
** @public
**/
function FreeResult($rs)
{
if (is_resource($rs)) @mssql_free_result($rs);
}
/** Used to get the text of the most recent error message on the
** current database connection. Returns the most recent error message
** as a string if such a message exists. Otherwise it returns boolean false.
** @returns string
** @public
**/
function GetLastMessage()
{
$strError = @mssql_get_last_message();
if (trim($strError) != "")
return str_replace("\r\n", "\r", $strError);
else
return false;
}
}
/** A class used to wrap PHP's MS-SQL Server connectivity functions. While it can be
** accessed directly, the recommended method is to access it through the wrapper
** cDatabases() class.
** @author Frank M. Kromann <[email protected]>
** @author Geoff A. Virgo <[email protected]> - internal documentation
**/
class cODBC extends cDBConstruct {
/** The class constructor undertakes no actions beyond returning boolean true.
** It is included merely for good style and against the needs of future expansion.
**/
function cODBC()
{
$this->cDBConstruct();
return true;
}
/** This method is used to connect to the specified ODBC server or DSN. All accepted
** arguments are strings, with $strDatabase being optional. If $strDatabase is specified
** the method will try to select that database.
** @returns void
** @public
**/
function Connect($strHost, $strUser, $strPassword, $strDatabase)
{
$this->conn = @odbc_connect($strHost, $strUser, $strPassword) or $this->_DBConnectionError();
$this->columns = 0;
$this->rows = 0;
}
/** Used to disconnect from the current FrontBase database connection.
** @returns void
** @public
**/
function Disconnect()
{
@odbc_close($this->conn);
$this->conn = null;
}
/** Used to execute SQL queries on the currently opened database connection.
** Updates the $columns and $rows variables from the cDBConstruct() class
** with the values specific to the passed query. Returns a resource identifier
** on success or false on failure.
** @returns int
** @public
**/
function Query($strSQL)
{
$this->columns = 0;
$this->rows = 0;
$rs = @odbc_exec($this->conn, $strSQL) or $this->_SQLError($strSQL,$this->GetLastMessage());
if ($rs) {
$this->columns = @odbc_num_fields($rs);
$this->rows = @odbc_num_rows($rs);
}
return $rs;
}
/** Used to get the name of the column specified by $col in the result set identifed by $rs.
** Returns a string containing the column's name on success an null on failure.
** @returns string
** @public
**/
function ColumnName($rs, $col)
{
if ($rs) return @odbc_field_name($rs, $col + 1);
}
/** Used to get the maximum length that column, $col, from result, $rs,
** can contain. Returns the maximum length as an integer on success
** and null on failure.
** @returns int
** @public
**/
function ColumnLength($rs, $col)
{
if ($rs) return @odbc_field_len($rs, $col + 1);
}
/** Used to get the datatype of the column, $col, from result set, $rs, can contain.
** Returns a the datatype as a string on success and null on error.
** @returns string
** @public
**/
function ColumnType($rs, $col)
{
if ($rs) return @odbc_field_type($rs, $col + 1);
}
/** Used to read the current returned row from result result, $rs, into a numerically
** indexed array. Returns an array containing the row's values indexed by column
** number or success, or false if no further rows exist in the result set.
** @returns array
** @public
**/
function FetchRow($rs,$type=2)
{
$rowData = array();
if (is_resource($rs)) {
if (@odbc_fetch_row($rs)) {
for ($i = 0; $i < $this->columns; $i++) {
if ($type==1) {
$rowData[@odbc_field_name($rs, $i + 1)] = @odbc_result($rs, $i + 1);
}
else if ($type==3) {
$result = @odbc_result($rs, $i + 1);
$rowData[@odbc_field_name($rs, $i + 1)] = $result;
$rowData[] = $result;
}
else {
$rowData[] = @odbc_result($rs, $i + 1);
}
}
}
}
unset($key);
unset($result);
return $rowData;
}
/** Used to get and return the number of rows in the current result set
** can contain.
** @returns int
** @public
**/
function NumRows($rs)
{
if (is_resource($rs)) return @odbc_num_rows($rs);
}
/** This function is currently not supported in PHP's Unified ODBC Functions and
** exists merely for consistency within the abstraction layer. It should be
** consider deprecated.
** @returns boolean
** @deprecated
** @private
**/
function NextResult($rs)
{
$ret = true;
/*
$ret = false;
if ($rs) {
if (@odbc_next_result($rs)) {
$this->columns = @odbc_num_fields($rs);
$this->rows = @odbc_num_rows($rs);
$ret = true;
}
else {
$this->columns = 0;
$this->rows = 0;
$ret = false;
}
}
*/
return $ret;
}
/** Used to free the current result set, $rs, from memory.
** @returns void
** @public
**/
function FreeResult($rs)
{
if ($rs) @odbc_free_result($rs);
}
/** Used to get the text of the most recent error message on the
** current database connection. Returns the most recent error message
** as a string if such a message exists. Otherwise it returns boolean false.
** @returns string
** @public
**/
function GetLastMessage()
{
if ($this->conn) {
$strError = @odbc_error($this->conn);
if ($strError)
return str_replace("\r\n", "\r", $strError);
else
return false;
}
else
return false;
}
}
/** A class used to wrap PHP's mySQL connectivity functions. While it can be
** accessed directly, the recommended method is to access it through the wrapper
** cDatabases() class.
** @author Geoff A. Virgo <[email protected]>
**/
class cMYSQL extends cDBConstruct {
/** The class constructor undertakes no actions beyond returning boolean true.
** It is included merely for good style and against the needs of future expansion.
**/
function cMYSQL()
{
$this->cDBConstruct();
return true;
}
/** This method is used to connect to the specified mySQL server. All accepted
** arguments are strings.
** @returns void
** @public
**/
function Connect($strHost, $strUser, $strPassword, $strDatabase)
{
$this->conn = @mysql_connect($strHost, $strUser, $strPassword) or $this->_DBConnectionError();
if (!@mysql_select_db($strDatabase, $this->conn)) {
$this->Disconnect();
$this->_DBSelectionError();
}
$this->columns = 0;
$this->rows = 0;
}
/** Used to disconnect from the current FrontBase database connection.