Latest news
Home » CodeIgniter » Check database exists in codeigniter

Check database exists in codeigniter

Load the Database Utility Class

Notice: Databse Connection should be already established before loading the above class.

<?php $this->load->dbutil(); ?>

loaded class can access the functions using the  following method:

<?php $this->dbutil->some_function() ?>

<?php $this->dbutil->list_databases(); ?>

the above function will  show an array of database names:

<?php $dbs_smarttips = $this->dbutil->list_databases(); ?>

<?php foreach ($dbs_smarttips as $db_name)
echo $db_name;


<?php $this->dbutil->database_exists(); ?>

use the above function to check whether a database exists or not . It will returns true or false.


if ($this->dbutil->database_exists('database_name'))
echo "Database exists";


Note: Replace database_name with the name of the database you are looking for. This function is case sensitive.

*********Your valuable comments will be help me to improve the article better.

Leave a Reply


Check Also

Export Database using codeigniter

Database Utility Class : CodeIgniter PHP script to download mysql db-codeigniter,Backup MySQL database with CodeIgniter ...