X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   General questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=66)
-   -   Logging SQL queries (https://forum.x-cart.com/showthread.php?t=78568)

xgarb 01-05-2024 10:28 AM

Logging SQL queries
 
Anyone know how to do this in 5.5?

I have this but it's wrong

Code:

        $entityManager = \XLite\Core\Database::getRepo('XC\ProductTags\Model\Tag')->getEntityManager();
        $entityManager->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());

        $repo = $entityManager->getRepository('XC\ProductTags\Model\Tag');
        $tags = $repo->findAll();


cflsystems 01-08-2024 06:07 AM

Re: Logging SQL queries
 
Are you trying to see what the actual sql query is or trying to fetch all records of a model? It's not clear.


Database::getEm() will give you the entity manager.
Database::getEm()->getConnection() will give you the connection
..... chain the rest as needed


or


Database::getRepo(Tag::class)->createQueryBuilder('t')->select('t')->getQuery()->getSQL();


You can dump it using dd() or dump() passing the above result as an argument or you can use the XC logging to log the query from that result. If the query has params you can get them by replacing getQSL with getParameters


All times are GMT -8. The time now is 02:03 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.