Note You can also browse to the Database Utility by opening the Application folder and then opening the Microsoft Office 2011 folder. Open the Office folder, and then double-click Microsoft Database Utility.app. In the Database Utility window, select the database that you. The Utility Rate Database (URDB) is a free storehouse of rate structure information from utilities in the United States. The URDB includes rates for utilities based on the authoritative list of U.S. Utility companies maintained by the U.S. Department of Energy’s Energy Information Administration.
The Database Utility Class contains methods that help you manage yourdatabase.
- Using the Database Utilities
- Backup Your Database
Important
In order to initialize the Utility class, your databasedriver must already be running, since the utilities class relies on it.
Load the Utility Class as follows:
You can also pass another database object to the DB Utility loader, in casethe database you want to manage isn’t the default one:
In the above example, we’re passing a custom database object as the firstparameter and then tell it to return the dbutil object, instead ofassigning it directly to $this->dbutil
.
Note
Both of the parameters can be used individually, just pass an emptyvalue as the first one if you wish to skip it.
Once initialized you will access the methods using the $this->dbutil
object:
Returns an array of database names:
Sometimes it’s helpful to know whether a particular database exists.Returns a boolean TRUE/FALSE. Usage example:
Database Utility
Note
Replace database_name with the name of the database you arelooking for. This method is case sensitive.
Permits you to optimize a table using the table name specified in thefirst parameter. Returns TRUE/FALSE based on success or failure:
Note
Not all database platforms support table optimization. It ismostly for use with MySQL.
Permits you to repair a table using the table name specified in thefirst parameter. Returns TRUE/FALSE based on success or failure:
Kartenmeister Database Utility
Note
Not all database platforms support table repairs.
Permits you to optimize the database your DB class is currentlyconnected to. Returns an array containing the DB status messages orFALSE on failure.
Note
Not all database platforms support database optimization. Itit is mostly for use with MySQL.
Permits you to generate a CSV file from a query result. The firstparameter of the method must contain the result object from yourquery. Example:
The second, third, and fourth parameters allow you to set the delimiternewline, and enclosure characters respectively. By default commas areused as the delimiter, “n” is used as a new line, and a double-quoteis used as the enclosure. Example:
Important
This method will NOT write the CSV file for you. Itsimply creates the CSV layout. If you need to write the fileuse the File Helper.
Permits you to generate an XML file from a query result. The firstparameter expects a query result object, the second may contain anoptional array of config parameters. Example:
Important
This method will NOT write the XML file for you. Itsimply creates the XML layout. If you need to write the fileuse the File Helper.
Permits you to backup your full database or individual tables. Thebackup data can be compressed in either Zip or Gzip format.
Note
This feature is only available for MySQL and Interbase/Firebird databases.
Note
For Interbase/Firebird databases, the backup file name is the only parameter.
$this->dbutil->backup(‘db_backup_filename’);
Note
Due to the limited execution time and memory available to PHP,backing up very large databases may not be possible. If your database isvery large you might need to backup directly from your SQL server viathe command line, or have your server admin do it for you if you do nothave root privileges.
Backup preferences are set by submitting an array of values to the firstparameter of the backup()
method. Example:
Preference | Default Value | Options | Description |
---|---|---|---|
tables | empty array | None | An array of tables you want backed up. If left blank all tables will beexported. |
ignore | empty array | None | An array of tables you want the backup routine to ignore. |
format | gzip | gzip, zip, txt | The file format of the export file. |
filename | the current date/time | None | The name of the backed-up file. The name is needed only if you are usingzip compression. |
add_drop | TRUE | TRUE/FALSE | Whether to include DROP TABLE statements in your SQL export file. |
add_insert | TRUE | TRUE/FALSE | Whether to include INSERT statements in your SQL export file. |
newline | “n” | “n”, “r”, “rn” | Type of newline to use in your SQL export file. |
foreign_key_checks | TRUE | TRUE/FALSE | Whether output should keep foreign key checks enabled. |
CI_DB_utility
¶backup
([$params = array()])¶Parameters: |
|
---|---|
Returns: | raw/(g)zipped SQL query string |
Return type: | string |
Perform a database backup, per user preferences.
database_exists
($database_name)¶Parameters: |
|
---|---|
Returns: | TRUE if the database exists, FALSE otherwise |
Return type: | bool |
Check for the existence of a database.
list_databases
()¶Returns: | Array of database names found |
---|---|
Return type: | array |
Retrieve a list of all the database names.
optimize_database
()¶Database Utility Images
Returns: | Array of optimization messages or FALSE on failure |
---|---|
Return type: | array |
Optimizes the database.
optimize_table
($table_name)¶Parameters: |
|
---|---|
Returns: | Array of optimization messages or FALSE on failure |
Return type: | array |
Optimizes a database table.
repair_table
($table_name)¶Parameters: |
|
---|---|
Returns: | Array of repair messages or FALSE on failure |
Return type: | array |
Repairs a database table.
csv_from_result
($query[, $delim = ', '[, $newline = 'n'[, $enclosure = '']]])¶Parameters: |
|
---|---|
Returns: | The generated CSV file as a string |
Return type: | string |
Translates a database result object into a CSV document.
xml_from_result
($query[, $params = array()])¶Parameters: |
|
---|---|
Returns: | The generated XML document as a string |
Return type: | string |
Translates a database result object into an XML document.