I have some php scripts that use mysqli() to connect to MySQL which is located on the same server. I currently have the connection stored outside of my sites root and I am using include() to make the connection.

For remote MySQL servers it is recommended to use an ssh connection. For my environment, should I take any other measures to secure my connection?

Also is it more of a concern that mysql is on the same server?

Lastly I am guessing I would want to prevent any errors resulting from the connection being displayed as they would give connection information.


Im also curious as to if/when I would want to close() these connections. I am guessing I would want to close them but only after I am done accessing the database on a particular page.


Still looking for the above information as of 12.11.2019

  • Most of the time remote connections are not allowed or at least VERY highly discouraged. Using ssh would be considered a minimum requirement if you do need to allow remote connections. You don't need to explicitly close connections. That is done when the PHP script is finished. Use try/catch for the connection to make sure no connection information gets "leaked". Also set your logging to always go to the PHP error log instead of having it displayed.
    – Dave
    Apr 13, 2020 at 13:28


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.