Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a message when not able to connect to database #1845

Closed
edirpedro opened this issue Sep 18, 2014 · 10 comments
Closed

Provide a message when not able to connect to database #1845

edirpedro opened this issue Sep 18, 2014 · 10 comments

Comments

@edirpedro
Copy link

Today my database crashed and the store shows me a bunch of error messages and part of the default OC theme, something very weird to see. It needs an error message here and stop running when not able to make a connection. Like WordPress does when this happens "Error establishing a database connection".

@jamesallsup
Copy link
Contributor

What database connection type are you using?

What error did you get?

Can you add a screenshot please.

@edirpedro
Copy link
Author

MySQL, using mysql, the mysql_connect could not recognize the hostname because a fail on my server. This is what users see when this happens (http://hub.edirpedro.com.br/arquivos/mysql_connect_error.png). It's not a professional crash, look at the default theme beeing displayed. It needs to check database connection fully before start running the store, connection and database needs to be available here.

@jamesallsup
Copy link
Contributor

You do not display errors on a live environment, disable them in the settings area for your store. Having them enabled is a security issue and is ONLY intended for development/ testing. If you disable then you will just get a white screen (handle that as you would like on your own store etc) - but you should enable error logging to the error.txt file under system/logs.

You cannot handle every single issue that php can throw with a custom message - it would take far too long.

@jamesallsup
Copy link
Contributor

Additionally, mysql_connect is being removed in PHP now, you need to use MySQLi engine.

@edirpedro
Copy link
Author

James, I think you didn't understand, the error exists, this option on Admin panel only works if database is available and this not apply here. What I'm telling is that there is no die() on the script if a database connection fails at startup and this do not depend of that option in Admin panel.

I made this test:

  • Installed OC using MySQLi;
  • Set on admin to show no error messages; (only works if database is available)
  • Changed DB informations in the store config.php to XXX
  • Open the store and the message is displayed.
Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2005): Unknown MySQL server host 'XXX' (22) in /Users/edir/Trabalho/Edir/octest/system/database/mysqli.php on line 6

Fatal error: Uncaught exception 'ErrorException' with message 'Error: Could not make a database link (2005) Unknown MySQL server host 'XXX' (22)' in /Users/edir/Trabalho/Edir/octest/system/database/mysqli.php:9 Stack trace: #0 /Users/edir/Trabalho/Edir/octest/system/library/db.php(13): DBMySQLi->__construct('XXX', 'xxx', 'xxx', 'octest') #1 /Users/edir/Trabalho/Edir/octest/index.php(40): DB->__construct('mysqli', 'XXX', 'xxx', 'xxx', 'octest') #2 {main} thrown in /Users/edir/Trabalho/Edir/octest/system/database/mysqli.php on line 9

If the connection uses old MySQL instead of MySQLi the results is like you see on the screenshot i provided before.

@edirpedro
Copy link
Author

James, I forgot to say, for MySQLi this is a security issue because it shows me the user and password on the message in Fatal Error DBMySQLi->__construct('XXX', 'xxx', 'xxx', 'octest').

@jamesallsup
Copy link
Contributor

Looking into it, this seems that it has already been resolved on the pending 1.5.6.5 release:

https://github.com/opencart/opencart/blob/v1.5.6.x/upload/system/database/mysqli.php

Apologies though as this had not been documented in the change log - which will be added now for future knowledge. As you mentioned the security concern is that the database details are exposed on a failed connect - that is what has been resolved but you will still get an error when trying to connect to a DB that is incorrect.

@kanenas
Copy link
Contributor

kanenas commented Oct 24, 2014

@jamesallsup sorry to bother you, but here http://www.opencart.com/index.php?route=download/download there is no v.1.5.6.5 to download!
Are you guys planning to release v.1.5.6.5 soon?

Thanks

@DS-Matt
Copy link
Contributor

DS-Matt commented Oct 24, 2014

@kanenas -

Opencart (at least to my knowledge) is only on active development for versions 2.X+. You can download version 2.0.0.0 at the opencart downloads link.

Best of luck!

DS-MATT

@jamesallsup
Copy link
Contributor

@kanenas @DS-Matt

We are still doing bug fixes for the 1.5.6.x branch, 1.5.6.5 will be available soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants