I am new to Codeigniter and trying to connect to dynamic database define by user, like we normally do in PHP.
Currently i am able to connect to database by using the setting mention in user guide and trying to access it like..
class ModelTest extends CI_Model
{
public function getdata()
{
$this->load->database();
$q=$this->db->query("SELECT * FROM users");
return $q->result();
}
}
Now i want to access it using the database define by the user, not the default like we use normally..
class Database{
// specify your own database credentials
private $host = 'mysql:host=localhost;dbname=satudent_enrollement';
private $username = 'root';
private $password = '';
public $conn;
// get the database connection
public function getConnection(){
$this->conn = null;
try{
$this->conn = new PDO($this->host , $this->username, $this->password);
}catch(PDOException $exception){
echo "Connection error: " . $exception->getMessage();
}
return $this->conn;
}
}
What I Want: To connect the Database using the database define by the user not the default.
Any help will be appreciated.