blob: 5bbf46810622e396f65ad52b8b474521741ef85c [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 {
36 return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name));
37 }
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 {
50 return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name));
51 }
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 /**
admina5e812c2006-09-25 02:17:30 +000079 * Version number query string
admin7b613c72006-09-24 18:05:17 +000080 *
81 * @access public
admina5e812c2006-09-25 02:17:30 +000082 * @return string
admin7b613c72006-09-24 18:05:17 +000083 */
admina5e812c2006-09-25 02:17:30 +000084 function _version()
admin7b613c72006-09-24 18:05:17 +000085 {
admina5e812c2006-09-25 02:17:30 +000086 return "SELECT version() AS ver";
87 }
88
89 // --------------------------------------------------------------------
90
91 /**
92 * Show table query
93 *
94 * Generates a platform-specific query string so that the table names can be fetched
95 *
96 * @access public
97 * @return string
98 */
99 function _show_tables()
100 {
101 return "SHOW TABLES FROM `".$this->db->database."`";
admin7b613c72006-09-24 18:05:17 +0000102 }
103
104 // --------------------------------------------------------------------
105
admina5e812c2006-09-25 02:17:30 +0000106 /**
107 * Show columnn query
108 *
109 * Generates a platform-specific query string so that the column names can be fetched
110 *
111 * @access public
112 * @param string the table name
113 * @return string
114 */
115 function _show_columns($table = '')
116 {
117 return "SHOW COLUMNS FROM ".$this->db->_escape_table($table);
118 }
119
120 // --------------------------------------------------------------------
121
122 /**
123 * Field data query
124 *
125 * Generates a platform-specific query so that the column data can be retrieved
126 *
127 * @access public
128 * @param string the table name
129 * @return object
130 */
131 function _field_data($table)
132 {
133 $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1";
134 $query = $this->db->query($sql);
135 return $query->field_data();
136 }
137
138
admin6ca6f942006-09-25 02:51:08 +0000139
admin7b613c72006-09-24 18:05:17 +0000140}
141
142?>