admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 1 | <?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 | */ |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 25 | class CI_DB_mysql_utility extends CI_DB_utility { |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 26 | |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 27 | /** |
| 28 | * Create database |
| 29 | * |
admin | 6cec6a5 | 2006-09-25 06:56:49 +0000 | [diff] [blame] | 30 | * @access private |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 31 | * @param string the database name |
| 32 | * @return bool |
| 33 | */ |
admin | 6cec6a5 | 2006-09-25 06:56:49 +0000 | [diff] [blame] | 34 | function _create_database($name) |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 35 | { |
admin | 6cec6a5 | 2006-09-25 06:56:49 +0000 | [diff] [blame] | 36 | return "CREATE DATABASE ".$name; |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | // -------------------------------------------------------------------- |
| 40 | |
| 41 | /** |
| 42 | * Drop database |
| 43 | * |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 44 | * @access private |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 45 | * @param string the database name |
| 46 | * @return bool |
| 47 | */ |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 48 | function _drop_database($name) |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 49 | { |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 50 | return "DROP DATABASE ".$name; |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | // -------------------------------------------------------------------- |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 54 | |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 55 | /** |
admin | 7249637 | 2006-09-25 03:44:04 +0000 | [diff] [blame] | 56 | * List databases |
| 57 | * |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 58 | * @access private |
admin | 7249637 | 2006-09-25 03:44:04 +0000 | [diff] [blame] | 59 | * @return bool |
| 60 | */ |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 61 | function _list_databases() |
admin | 7249637 | 2006-09-25 03:44:04 +0000 | [diff] [blame] | 62 | { |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 63 | return "SHOW DATABASES"; |
admin | 7249637 | 2006-09-25 03:44:04 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | // -------------------------------------------------------------------- |
| 67 | |
| 68 | /** |
admin | 4ceac2d | 2006-09-25 06:40:16 +0000 | [diff] [blame] | 69 | * Drop Table |
| 70 | * |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 71 | * @access private |
admin | 4ceac2d | 2006-09-25 06:40:16 +0000 | [diff] [blame] | 72 | * @return bool |
| 73 | */ |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 74 | function _drop_table($table) |
admin | 4ceac2d | 2006-09-25 06:40:16 +0000 | [diff] [blame] | 75 | { |
admin | 83b05a8 | 2006-09-25 21:06:46 +0000 | [diff] [blame] | 76 | return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); |
admin | 4ceac2d | 2006-09-25 06:40:16 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | // -------------------------------------------------------------------- |
| 80 | |
| 81 | /** |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 82 | * Version number query string |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 83 | * |
| 84 | * @access public |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 85 | * @return string |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 86 | */ |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 87 | function _version() |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 88 | { |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 89 | return "SELECT version() AS ver"; |
| 90 | } |
| 91 | |
| 92 | // -------------------------------------------------------------------- |
| 93 | |
| 94 | /** |
| 95 | * Show table query |
| 96 | * |
| 97 | * Generates a platform-specific query string so that the table names can be fetched |
| 98 | * |
| 99 | * @access public |
| 100 | * @return string |
| 101 | */ |
| 102 | function _show_tables() |
| 103 | { |
| 104 | return "SHOW TABLES FROM `".$this->db->database."`"; |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | // -------------------------------------------------------------------- |
| 108 | |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 109 | /** |
| 110 | * Show columnn query |
| 111 | * |
| 112 | * Generates a platform-specific query string so that the column names can be fetched |
| 113 | * |
| 114 | * @access public |
| 115 | * @param string the table name |
| 116 | * @return string |
| 117 | */ |
| 118 | function _show_columns($table = '') |
| 119 | { |
| 120 | return "SHOW COLUMNS FROM ".$this->db->_escape_table($table); |
| 121 | } |
| 122 | |
| 123 | // -------------------------------------------------------------------- |
| 124 | |
| 125 | /** |
| 126 | * Field data query |
| 127 | * |
| 128 | * Generates a platform-specific query so that the column data can be retrieved |
| 129 | * |
| 130 | * @access public |
| 131 | * @param string the table name |
| 132 | * @return object |
| 133 | */ |
| 134 | function _field_data($table) |
| 135 | { |
admin | 6cec6a5 | 2006-09-25 06:56:49 +0000 | [diff] [blame] | 136 | return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 140 | |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | ?> |