Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Logging SQL queries

 
Reply
   X-Cart forums > X-Cart 5 > General questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 01-05-2024, 10:28 AM
 
xgarb xgarb is offline
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 263
 

Default 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();
__________________
Core version: 5.5.xx
Reply With Quote
  #2  
Old 01-08-2024, 06:07 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,197
 

Default 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
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > General questions (X-Cart 5)



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 04:22 PM.

   

 
X-Cart forums © 2001-2020