blob: 39dc2cca217cece7eef6004f35879693c892e810 [file] [log] [blame]
admin7b613c72006-09-24 18:05:17 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * Code Igniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author Rick Ellis
9 * @copyright Copyright (c) 2006, pMachine, Inc.
10 * @license http://www.codeignitor.com/user_guide/license.html
11 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * Database Utility Class
20 *
21 * @category Database
22 * @author Rick Ellis
23 * @link http://www.codeigniter.com/user_guide/database/
24 */
25class CI_DB_utility {
26
27
28
29 // --------------------------------------------------------------------
30
31 /**
32 * Database Version Number. Returns a string containing the
33 * version of the database being used
34 *
35 * @access public
36 * @return string
37 */
38 function version()
39 {
40 if (FALSE === ($sql = $this->_version()))
41 {
42 if ($this->db_debug)
43 {
44 return $this->display_error('db_unsupported_function');
45 }
46 return FALSE;
47 }
48
49 if ($this->dbdriver == 'oci8')
50 {
51 return $sql;
52 }
53
54 $query = $this->query($sql);
55 $row = $query->row();
56 return $row->ver;
57 }
58
59 // --------------------------------------------------------------------
60
61 /**
62 * Returns an array of table names
63 *
64 * @access public
65 * @return array
66 */
67 function tables()
68 {
69 if (FALSE === ($sql = $this->_show_tables()))
70 {
71 if ($this->db_debug)
72 {
73 return $this->display_error('db_unsupported_function');
74 }
75 return FALSE;
76 }
77
78 $retval = array();
79 $query = $this->query($sql);
80
81 if ($query->num_rows() > 0)
82 {
83 foreach($query->result_array() as $row)
84 {
85 if (isset($row['TABLE_NAME']))
86 {
87 $retval[] = $row['TABLE_NAME'];
88 }
89 else
90 {
91 $retval[] = array_shift($row);
92 }
93 }
94 }
95
96 return $retval;
97 }
98
99 // --------------------------------------------------------------------
100
101 /**
102 * Determine if a particular table exists
103 * @access public
104 * @return boolean
105 */
106 function table_exists($table_name)
107 {
108 return ( ! in_array($this->dbprefix.$table_name, $this->tables())) ? FALSE : TRUE;
109 }
110
111 // --------------------------------------------------------------------
112
113 /**
114 * Fetch MySQL Field Names
115 *
116 * @access public
117 * @param string the table name
118 * @return array
119 */
120 function field_names($table = '')
121 {
122 if ($table == '')
123 {
124 if ($this->db_debug)
125 {
126 return $this->display_error('db_field_param_missing');
127 }
128 return FALSE;
129 }
130
131 if (FALSE === ($sql = $this->_show_columns($this->dbprefix.$table)))
132 {
133 if ($this->db_debug)
134 {
135 return $this->display_error('db_unsupported_function');
136 }
137 return FALSE;
138 }
139
140 $query = $this->query($sql);
141
142 $retval = array();
143 foreach($query->result_array() as $row)
144 {
145 if (isset($row['COLUMN_NAME']))
146 {
147 $retval[] = $row['COLUMN_NAME'];
148 }
149 else
150 {
151 $retval[] = current($row);
152 }
153 }
154
155 return $retval;
156 }
157
158 // --------------------------------------------------------------------
159
160 /**
161 * Returns an object with field data
162 *
163 * @access public
164 * @param string the table name
165 * @return object
166 */
167 function field_data($table = '')
168 {
169 if ($table == '')
170 {
171 if ($this->db_debug)
172 {
173 return $this->display_error('db_field_param_missing');
174 }
175 return FALSE;
176 }
177
178 return $this->_field_data($this->dbprefix.$table);
179 }
180
181 // --------------------------------------------------------------------
182
183 /**
184 * Primary
185 *
186 * Retrieves the primary key. It assumes that the row in the first
187 * position is the primary key
188 *
189 * @access public
190 * @param string the table name
191 * @return string
192 */
193 function primary($table = '')
194 {
195 $fields = $this->field_names($table);
196
197 if ( ! is_array($fields))
198 {
199 return FALSE;
200 }
201
202 return current($fields);
203 }
204
admin7b613c72006-09-24 18:05:17 +0000205
adminbb1d4392006-09-24 20:14:38 +0000206
207
208
209 function create_database()
admin7b613c72006-09-24 18:05:17 +0000210 {
admin7b613c72006-09-24 18:05:17 +0000211 }
212
adminbb1d4392006-09-24 20:14:38 +0000213 function drop_database()
admin7b613c72006-09-24 18:05:17 +0000214 {
adminbb1d4392006-09-24 20:14:38 +0000215 }
admin7b613c72006-09-24 18:05:17 +0000216
adminbb1d4392006-09-24 20:14:38 +0000217 function show_databases()
218 {
219 }
220
221 function create_table()
222 {
223 }
224
225 function alter_table()
226 {
227 }
228
229 function create_index()
230 {
231 }
232
233 function drop_index()
234 {
235 }
236
237 function optimize()
238 {
239 }
admin7b613c72006-09-24 18:05:17 +0000240
admin7b613c72006-09-24 18:05:17 +0000241
242
243}
244
245?>