Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL database trying to update info but not appearing on website

Tags:

php

mysql

symfony

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?

like image 234
Adam Silva Avatar asked Oct 16 '15 12:10

Adam Silva


People also ask

What are the common causes that you are unable to connect your website to the MySQL database?

The most common reason for this problem is that the database credentials in your website's application configuration file are invalid. Verify them and check if your MySQL user has been added to access the database. You can manage your MySQL databases, users and their password from Site Tools -> MySQL Manager.


2 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.

like image 187
HPierce Avatar answered Oct 20 '22 21:10

HPierce


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.

like image 10
David Soussan Avatar answered Oct 20 '22 19:10

David Soussan