blob: 23c4e094d3938a18192fe89e64398911d25b2ab2 [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 * MySQL Utility Class
20 *
21 * @category Database
22 * @author Rick Ellis
23 * @link http://www.codeigniter.com/user_guide/database/
24 */
admina5e812c2006-09-25 02:17:30 +000025class CI_DB_mysql_utility extends CI_DB_utility {
admin7b613c72006-09-24 18:05:17 +000026
admin6ca6f942006-09-25 02:51:08 +000027 /**
28 * Create database
29 *
30 * @access public
31 * @param string the database name
32 * @return bool
33 */
34 function create_database($name)
35 {
admin4ceac2d2006-09-25 06:40:16 +000036 return $this->db->query("CREATE DATABASE ".$name);
admin6ca6f942006-09-25 02:51:08 +000037 }
38
39 // --------------------------------------------------------------------
40
41 /**
42 * Drop database
43 *
44 * @access public
45 * @param string the database name
46 * @return bool
47 */
48 function drop_database($name)
49 {
admin4ceac2d2006-09-25 06:40:16 +000050 return $this->db->query("DROP DATABASE ".$name);
admin6ca6f942006-09-25 02:51:08 +000051 }
52
53 // --------------------------------------------------------------------
admina5e812c2006-09-25 02:17:30 +000054
admin7b613c72006-09-24 18:05:17 +000055 /**
admin72496372006-09-25 03:44:04 +000056 * List databases
57 *
58 * @access public
59 * @return bool
60 */
61 function list_databases()
62 {
63 $query = $this->db->query("SHOW DATABASES");
64 $dbs = array();
65 if ($query->num_rows() > 0)
66 {
67 foreach ($query->result_array() as $row)
68 {
69 $dbs[] = current($row);
70 }
71 }
72
73 return $dbs;
74 }
75
76 // --------------------------------------------------------------------
77
78 /**
admin4ceac2d2006-09-25 06:40:16 +000079 * Drop Table
80 *
81 * @access public
82 * @return bool
83 */
84 function drop_table($table)
85 {
86 "DROP TABLE IF EXISTS ".$this->db->_escape_table($name);
87 }
88
89 // --------------------------------------------------------------------
90
91 /**
admina5e812c2006-09-25 02:17:30 +000092 * Version number query string
admin7b613c72006-09-24 18:05:17 +000093 *
94 * @access public
admina5e812c2006-09-25 02:17:30 +000095 * @return string
admin7b613c72006-09-24 18:05:17 +000096 */
admina5e812c2006-09-25 02:17:30 +000097 function _version()
admin7b613c72006-09-24 18:05:17 +000098 {
admina5e812c2006-09-25 02:17:30 +000099 return "SELECT version() AS ver";
100 }
101
102 // --------------------------------------------------------------------
103
104 /**
105 * Show table query
106 *
107 * Generates a platform-specific query string so that the table names can be fetched
108 *
109 * @access public
110 * @return string
111 */
112 function _show_tables()
113 {
114 return "SHOW TABLES FROM `".$this->db->database."`";
admin7b613c72006-09-24 18:05:17 +0000115 }
116
117 // --------------------------------------------------------------------
118
admina5e812c2006-09-25 02:17:30 +0000119 /**
120 * Show columnn query
121 *
122 * Generates a platform-specific query string so that the column names can be fetched
123 *
124 * @access public
125 * @param string the table name
126 * @return string
127 */
128 function _show_columns($table = '')
129 {
130 return "SHOW COLUMNS FROM ".$this->db->_escape_table($table);
131 }
132
133 // --------------------------------------------------------------------
134
135 /**
136 * Field data query
137 *
138 * Generates a platform-specific query so that the column data can be retrieved
139 *
140 * @access public
141 * @param string the table name
142 * @return object
143 */
144 function _field_data($table)
145 {
146 $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1";
147 $query = $this->db->query($sql);
148 return $query->field_data();
149 }
150
151
admin6ca6f942006-09-25 02:51:08 +0000152
admin7b613c72006-09-24 18:05:17 +0000153}
154
155?>