Home » Php » php – MySQL database trying to update info but not appearing on website

php – MySQL database trying to update info but not appearing on website

Posted by: admin July 12, 2020 Leave a comment

Questions:

I have a website in Symfony linked to a a MySQL database. The website is having some troubles, so I have to update the information in the database. The thing is, when I update on the database, it stays updated there but on the website it doesn’t show any changes.

For example, a user is registered. I go to the database to change the email so I can register another account with the same email. The database is updated with the new email, but on the website it says that the old email is still in use.

I know that I am updating the right database, because when I register a new client on the website, it appears on the database. Any ideas on to why this might be happening?

How to&Answers:

Like Angel Iliikov mentions in the comments, it’s very likely a caching issue. The following suggestions assumes you have access to the command line – which a typical Symfony user should. If you don’t already have it, most hosting providers allow you to get SSH access.

Clear the following caches:

1. Symfony’s cache

Symfony will store a lot of data in the cache files to prevent it from having to process requests from scratch. When Symfony apps go wonky, a very common fix is to clear this cache and retry. The standard way to clear this cache is with a console command run at your project’s root directory:

$ app/console cache:clear

If you run into issues, David Soussan answer provides more information on this one.

2. Doctrine’s cache

According to commenters on another question (formatted by me):

The doctrine cache is often stored in apc rather than in the file
system so removing the cache files would not help. The general app/console cache:clear is only for the symfony (app) cache. I don’t think it clears the doctrine cache(s).

-caponica

Alternative PHP Cache (APC) is an optional component enabled in php.ini. It’s possible Doctrine is caching information there as well if it happens to be enabled.

The accepted answer on the previously mentioned question provides an answer for clearing Doctrine’s cache:

 $ app/console doctrine:cache:clear-metadata 
 $ app/console doctrine:cache:clear-query  
 $ app/console doctrine:cache:clear-result

-amitchhajer

3. Your browser’s cache

This is very unlikely to be causing any issues. But if you are doing something to send caching headers over HTTP – it’s possible that the application would have properly updated the data, but your browser is displaying an old page.

Each browser has a different way of clearing cache. Google provides support for how to do it Chrome. and Mozilla provides support for how do it in Firefox.


If clearing the cache doesn’t solve your problem, it’s likely a problem with your application or workflow and will need debugging. A few things you can try:

  1. Make sure you really updated the correct database. Confirm this
    on two separate DB clients.

  2. Create your own Symfony
    command

    where the only thing you do is query the database. If it returns the correct result, you should check that other components are using the same query. If not, check your config/parameters to ensure you’re using the right database.

Answer:

If your Symfony application is not showing the updated database record that is because it is using the cache which still contains the old data. This is often a problem with Symfony, refreshing the page just reloads from the cache. Try clearing the cache first. Now, very often cache:clear does not work from the command line, I’ve had it happen all the time and never really understood why. The answer is to just delete all the cache files, as per Fabien Potencier’s tip: http://fabien.potencier.org/a-symfony-tip-clear-the-cache-without-the-command-line.html. That works and is my go-to solution for when eg; composer update did not clear the cache afterwards. In fact I got into the habit of just deleting the cache files on my dev machine before doing composer install or update.

Answer:

Adam,

Use these commands to clear your cache:

# dev environment
$ app/console cache:clear

# production environment
$ app/console cache:clear --env=prod

Answer:

I had problems using the mysql database supplied by my host server at first but then I installed the latest mysql database version available in softaculus inside my host server and then I was able to access mysql inside softaculus or directly by the url (www.mypage.com/mysql). Finally it works perfectly. You can try to do something similar.