Database Utility

Posted on  by 



  1. Database Utility
  2. Kartenmeister Database Utility
  3. Database Utility Images

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.

Utility
  • 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->dbutilobject:

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

Database UtilityUtility

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:

PreferenceDefault ValueOptionsDescription
tablesempty arrayNoneAn array of tables you want backed up. If left blank all tables will beexported.
ignoreempty arrayNoneAn array of tables you want the backup routine to ignore.
formatgzipgzip, zip, txtThe file format of the export file.
filenamethe current date/timeNoneThe name of the backed-up file. The name is needed only if you are usingzip compression.
add_dropTRUETRUE/FALSEWhether to include DROP TABLE statements in your SQL export file.
add_insertTRUETRUE/FALSEWhether 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_checksTRUETRUE/FALSEWhether output should keep foreign key checks enabled.
class CI_DB_utility
backup([$params = array()])
Parameters:
  • $params (array) – An associative array of options
Returns:

raw/(g)zipped SQL query string

Return type:

string

Perform a database backup, per user preferences.

database_exists($database_name)
Parameters:
  • $database_name (string) – Database name
Returns:

TRUE if the database exists, FALSE otherwise

Return type:

bool

Check for the existence of a database.

Database Utility
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:
  • $table_name (string) – Name of the table to optimize
Returns:

Array of optimization messages or FALSE on failure

Return type:

array

Optimizes a database table.

repair_table($table_name)
Information utility examples
Parameters:
  • $table_name (string) – Name of the table to repair
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:
  • $query (object) – A database result object
  • $delim (string) – The CSV field delimiter to use
  • $newline (string) – The newline character to use
  • $enclosure (string) – The enclosure delimiter to use
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:
  • $query (object) – A database result object
  • $params (array) – An associative array of preferences
Returns:

The generated XML document as a string

Return type:

string

Translates a database result object into an XML document.





Coments are closed