Php updating a static variable

As I mentioned previously, it's not good practice to keep those in the database connection script, especially if the PHP files are inside the document root (which means they will be accessible directly from the web).A server error (malfunction or intentional) could cause those files to be displayed as text, revealing your database credentials to everyone viewing it at the time.It's insecure, uses outdated methods, does not protect from change and promotes bad habits, but it does work.Let's look at an example: Let's break the process step-by-step, and see how we can improve on the example above.I will explain the reasoning behind each step and compare it with the less desired alternative.This tutorial does not cover installing My SQL on your web server - it focuses on using it in PHP.

Note that unless you close the connection to the database (as the initial example showed), you only need to connect to the database once during the lifetime of the script.The first order of business is connecting to the database.With My SQLi, the function that does that is Something is missing here though - where do the database credentials come from?Try searching for "php mysql tutorial" and see what you find - it ain't pretty.In this tutorial I will try and show a simple, yet forward thinking and secure way to use My SQL in PHP.

Php updating a static variable