Welcome Guest, Not a member yet? Register   Sign In
Get database name
#1

[eluser]cimmerian[/eluser]
Hi,

What is the best way to dynamically read the database configuration? I need access to the name of the current database.
#2

[eluser]Jan_1[/eluser]
? - What do you want to do?
#3

[eluser]cimmerian[/eluser]
I'm writing a method that performs queries on the information_schema database. It needs to know the name of active database. I solved it by using a MySQL query:

Code:
$this->db->select('DATABASE() AS database_name');
$rows = $this->db->get()->result();
$database = $rows[0]->database_name;
#4

[eluser]Rodrigo Passos[/eluser]
Have you found a solution or still using the query? I'm in the same situation.
#5

[eluser]cimmerian[/eluser]
No, I'm still using the query.
#6

[eluser]WanWizard[/eluser]
What is wrong with:
Code:
echo $this->db->database;
#7

[eluser]Rodrigo Passos[/eluser]
Thanks you! I couldn't find that in the documentation anywhere... can you send a link to it?
#8

[eluser]WanWizard[/eluser]
It isn't in the documentation.

When you have questions about the internals of CI, it's worth having a look at the code, in this case ./system/database/DB_driver.php.
#9

[eluser]Rodrigo Passos[/eluser]
Thanks! I will do that!




Theme © iAndrew 2016 - Forum software by © MyBB