How to get the MySQL database connection resource from Kohana?
I would like to get the default MySQL database connection in Kohana for use with a third-party library. How can I do that?
So far I have the following code:
开发者_C百科$db = Database::instance('default');
$db->connect(); // After this, how can I retrieve the MySQL connection instance?
The connection is stored in a protected property in the Database class.
You can see this variable in the Database class and where it's being set in the MySQL class. If you wanted to have access to this variable then you can overload the Database class to provide a getter for it.
Well, I don't know why do you need that, but Database::instance('default') each time returns a singleton instance, so you can use it anywhere in your code. 'default' can be considered as a connection name.
精彩评论