1 |
jonen |
1.1 |
<?php |
2 |
|
|
|
3 |
|
|
/** |
4 |
|
|
* This file contains the SQLDataListSource child class |
5 |
|
|
* that uses the ADODB DB object to talk to the DB. |
6 |
|
|
* |
7 |
|
|
* you can check out ADODB from |
8 |
|
|
* http://php.weblogs.com/ADODB |
9 |
|
|
* |
10 |
|
|
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
11 |
|
|
* @package phpHtmlLib |
12 |
|
|
*/ |
13 |
|
|
|
14 |
|
|
/** |
15 |
|
|
* This requires the SQLDataListSource |
16 |
|
|
* parent class |
17 |
|
|
* |
18 |
|
|
*/ |
19 |
|
|
include_once($phphtmllib."/widgets/data_list/SQLDataListSource.inc"); |
20 |
|
|
|
21 |
|
|
/** |
22 |
|
|
* NOTE: |
23 |
|
|
* You'll need to include the base |
24 |
|
|
* ADODB include file prior to using this |
25 |
|
|
* file. |
26 |
|
|
* include_once( 'adodb.inc.php' ); |
27 |
|
|
* |
28 |
|
|
*/ |
29 |
|
|
|
30 |
|
|
|
31 |
|
|
/** |
32 |
|
|
* This SQLDataListSource child class interacts with |
33 |
|
|
* with the specific DB via the php ADODB DB abstraction |
34 |
|
|
* objects. |
35 |
|
|
* |
36 |
|
|
* How to use? |
37 |
|
|
* in the DataList child's get_data_source() method |
38 |
|
|
* you pass in the already connected PEAR DB object |
39 |
|
|
* in to the constructor. PEARSQLDataListSource |
40 |
|
|
* takes care of the rest. |
41 |
|
|
* |
42 |
|
|
*/ |
43 |
|
|
class ADODBSQLDataListSource extends SQLDataListSource { |
44 |
|
|
|
45 |
|
|
/** |
46 |
|
|
* This var holds the Database object |
47 |
|
|
* that is used to do the sql queries |
48 |
|
|
* It is assumed that the db is already |
49 |
|
|
* connected to, and the object provides |
50 |
|
|
* 2 methods: |
51 |
|
|
* query() - execute a sql query |
52 |
|
|
*/ |
53 |
|
|
var $_db = NULL; |
54 |
|
|
|
55 |
|
|
/** |
56 |
|
|
* this holds the query result from the |
57 |
|
|
* PEAR::DB->query() call |
58 |
|
|
* |
59 |
|
|
*/ |
60 |
|
|
var $_result = NULL; |
61 |
|
|
|
62 |
|
|
|
63 |
|
|
/** |
64 |
|
|
* The constructor is used to pass in the |
65 |
|
|
* PEAR DB object that has already been |
66 |
|
|
* created and connected to the db. |
67 |
|
|
* |
68 |
|
|
* @param ADONewConnection::Execute object - MUST BE CONNECTED |
69 |
|
|
*/ |
70 |
|
|
function ADODBSQLDataListSource( &$db ) { |
71 |
|
|
$this->set_db_object( $db ); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
/** |
75 |
|
|
* Set the DB object we will use |
76 |
|
|
* to talk to the DB. |
77 |
|
|
* |
78 |
|
|
* @param object - $db the babw_db object. |
79 |
|
|
* |
80 |
|
|
*/ |
81 |
|
|
function set_db_object( &$db ) { |
82 |
|
|
$this->_db = &$db; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
function do_query() { |
86 |
|
|
$this->_result = $this->_db->SelectLimit($this->_query, |
87 |
|
|
$this->get_limit(), |
88 |
|
|
$this->get_offset()); |
89 |
|
|
if (!$this->_result) { |
90 |
|
|
$msg = $this->_result->ErrorMsg(); |
91 |
|
|
user_error("ADODBSQLDataListSource::do_query() - query failed : ".$msg); |
92 |
|
|
} |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
/** |
98 |
|
|
* This function gets the next data row |
99 |
|
|
* from the query() |
100 |
|
|
* |
101 |
|
|
* @return array() |
102 |
|
|
*/ |
103 |
|
|
function get_next_data_row() { |
104 |
|
|
return $this->_result->FetchRow(); |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
/** |
108 |
|
|
* This function builds the limit |
109 |
|
|
* clause portion of a DB query. |
110 |
|
|
* |
111 |
|
|
* @return string - the limit portion of |
112 |
|
|
* the query. |
113 |
|
|
*/ |
114 |
|
|
function build_limit_clause($offset, $limit) { |
115 |
|
|
return NULL; |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
/** |
119 |
|
|
* find the number of rows to be returned |
120 |
|
|
* from a query from a table and where clause |
121 |
|
|
* |
122 |
|
|
* @param string $table - the table to count from |
123 |
|
|
* @param string $where_clause - a where clause |
124 |
|
|
* |
125 |
|
|
* @return int the # of rows |
126 |
|
|
*/ |
127 |
|
|
function count($tables, $where_clause='', $count_clause='*') { |
128 |
|
|
$query = "select count(".$count_clause.") as COUNT from ".$tables." ".$where_clause; |
129 |
|
|
$result = $this->_db->Execute($query); |
130 |
|
|
if (!$result) { |
131 |
|
|
$msg = $result->ErrorMsg(); |
132 |
|
|
user_error("ADODBSQLDataListSource::count() - query failed : ".$msg); |
133 |
|
|
} |
134 |
|
|
$value = $result->FetchRow(); |
135 |
|
|
return ($value ? (int)$value["COUNT"] : NULL); |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
?> |