简体   繁体   中英

Access CakePHP database connection

I'm looking for a way to access the database object CakePHP uses to make its calls to the database.

I have a class I wrote outside of CakePHP that uses the database. 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.

you can use DboSource Class for accessing Database and making database calls.
DboSource Class API doc

getConnection

Get the underlying connection object.

$db= &ConnectionManager::getDataSource('datasourceName'); // as defined in DATABASE.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM