how to check connection is build properly in codeigniter after configure database.php file? -


this controller code setting hostname,username,password,database_name programmatically & it's work in code

  function submit_installation()     {         $this->load->helper('url');         $this->load->helper('form');         $this->load->database();      if($_post)     {         //--------------------to config database file----------------------         $old_hostname = '$db[\'default\'][\'hostname\']';         $old_username = '$db[\'default\'][\'username\']';         $old_password = '$db[\'default\'][\'password\']';        $old_database = '$db[\'default\'][\'database\']';         $filename = "./application/config/database.php";           $file = file($filename);          foreach( $file $key=>$line ) {             if( false !== strpos($line, $old_hostname) )             {                 $file[$key]=$old_hostname."='".$_post['hostname']."';\n";             }             elseif( false !== strpos($line, $old_username) )             {                 $file[$key]=$old_username."='".$_post['username']."';\n";             }             elseif( false !== strpos($line, $old_password) )                {                   $file[$key]=$old_password."='".$_post['password']."';\n";               }             elseif( false !== strpos($line, $old_database) )             {                 $file[$key]=$old_database."='".$_post['database']."';\n";             }         }           file_put_contents($filename, $file); } } 

in database.php following code show database setting after execute controller file & changes made in database.php file.

    <?php  $active_group = 'default'; $active_record = true  $db['default']['hostname']='xxx';  $db['default']['username']='abc';  $db['default']['password']='abc';  $db['default']['database']='xyz';     $db['default']['dbprefix'] = '';     $db['default']['pconnect'] = true;     $db['default']['db_debug'] = false;     $db['default']['cache_on'] = false;     $db['default']['cachedir'] = '';     $db['default']['char_set'] = 'utf8';     $db['default']['dbcollat'] = 'utf8_general_ci';     $db['default']['swap_pre'] = '';     $db['default']['autoinit'] = true;     $db['default']['stricton'] = false; 

so how check database connection made or not using back-end code?

i think have try one:

$db_host        = 'localhost'; $db_user        = 'abc'; $db_pass        = 'xyz'; $db_database    = 'qwerty';  $link = mysql_connect($db_host,$db_user,$db_pass) or die('unable establish db connection'); 

this 1 easy method.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -