7

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Adam Silva
  • 1,013
  • 18
  • 48
  • 6
    Please see how to give a [mcve] – SierraOscar Oct 16 '15 at 12:24
  • 8
    Either cache or you are updating the wrong database :) – Angel Iliikov Oct 16 '15 at 12:29
  • 2
    If you are using `FOSUserBundle` make sure you are updating the `email` as well as `email_canonical`. – qooplmao Oct 16 '15 at 13:34
  • @AngelIliikov I already cleared the cache multiple times, and it still doesn't work. And it's updating the right database, because on the website when I register a new client, it appears on that database. – Adam Silva Oct 16 '15 at 18:52
  • @MacroMan I saw that, but there is no code to post. I just wanted to know the possibilities for what could be causing this problem.. – Adam Silva Oct 18 '15 at 21:04
  • show us your code which check for availability of emails for new user in database! show us proof (screenshot) of what data is in your table – Alex Oct 18 '15 at 21:54
  • 2
    Sorry, but there's an infinite number of possibilities. You simply must give us more information if you want any help here. Are you using Doctrine? Or accessing the database using PDO maybe? Are you using any 3rd party bundles for user management? Which ones? Is this reproducible in a dev environment and production environment? When you say "I already cleared the cache" did you clear the **server application's cache**? or your **browsers cache**? – HPierce Oct 18 '15 at 23:58
  • try looking for a username column, if that also saves the email address then that might be the reason behind it. – Shairyar Oct 19 '15 at 11:16
  • @Baig There are several columns, including a username column and an e-mail column – Adam Silva Oct 20 '15 at 01:16
  • 1
    @HPierce We're using Doctrine. Also on the file directory, there is Propel plugin and Protocolous plugin. I cleared the browsers cache... – Adam Silva Oct 20 '15 at 12:16
  • I wish I could get those 100 reputations =( but, how should I give an answer without code sample? Please provide some code, and so I could say: "your code is right, and so the problem is the cache". =) – Maduro Oct 25 '15 at 20:36

4 Answers4

13

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.

Community
  • 1
  • 1
HPierce
  • 7,249
  • 7
  • 33
  • 49
  • Thanks. Technically I do have access to the SSH, but I can't seem to connect to it right now... I'm trying to figure that out, then try your solution. – Adam Silva Oct 21 '15 at 16:24
  • Yes, the problem was with the cache. Since this answer is more complete and detailed, I will award you the rep :) Thanks – Adam Silva Oct 25 '15 at 23:14
10

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.

David Soussan
  • 2,698
  • 1
  • 16
  • 19
  • The application is being hosted by cPanel. Do I delete the cache files in the file adminstrator or do I delete them in WHM? – Adam Silva Oct 20 '15 at 17:20
  • Go directly to the app/cache folder and delete all the files using whatever tool gives you access to those files. If cPanel gives you a file administrator then use that. – David Soussan Oct 20 '15 at 17:24
  • But it's weird, because I just deleted the cache (I downloaded a backup before) from the /cache folder at the root directory. Then I deleted a user from the database and tried to register again with the same email, and it's still saying that the email exists :/ So I'm guessing it didn't do anything... – Adam Silva Oct 20 '15 at 18:13
  • Have you actually deleted the row or just flagged it as deleted? Also, are you using the fos user bundle? – David Soussan Oct 20 '15 at 19:06
4

Adam,

Use these commands to clear your cache:

# dev environment
$ app/console cache:clear

# production environment
$ app/console cache:clear --env=prod
Reformat Code
  • 307
  • 1
  • 3
1

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.

  • Since cPanel is being used, from what I was told, we have to use the same version of mySQL as cPanel. So we cannot update it without cPanel doing it first – Adam Silva Oct 20 '15 at 01:18