[英]Access CakePHP database connection
I'm looking for a way to access the database object CakePHP uses to make its calls to the database. 我正在寻找一种访问CakePHP用于调用数据库的数据库对象的方法。
I have a class I wrote outside of CakePHP that uses the database. 我在CakePHP之外编写了一个使用数据库的类。 Instead of opening its own connection, I thought it would be nice to just use one that may already be open. 我认为不用打开自己的连接,而只使用可能已经打开的连接会很好。
I have CakePHP set up to use MySQLi and the class I built uses MySQLi as well. 我将CakePHP设置为使用MySQLi,而我建立的类也使用MySQLi。
you can use DboSource Class for accessing Database and making database calls. 您可以使用DboSource类访问数据库并进行数据库调用。
DboSource Class API doc DboSource类API文档
getConnection
$db= &ConnectionManager::getDataSource('datasourceName'); // as defined in DATABASE.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.