I have that $db, that I will use again and again to connect to the database. How do I put this in a central location so if I change my db I will not have to rewrite a bunch of lines of code? Everything I've tried so far just gives me an error concerning variable scope, the variable is not declared in my functions, so I am forced to simply connect and use the $db object everytime I need to access the database.TLDR: How do I create the $db object once, and then use it again and again. Just looking for a general idea here.  function input_registration ($email, $password) {$email_clean = htmlspecialchars($email);$password_clean = htmlspecialchars($password);$hash = md5($password_clean);$db = new PDO(mysql:host=localhost;dbname=users, root, );try {$statement = $db->prepare(INSERT into userinfo(email, hash) VALUES (:email, :hash));$array_parameters = array(    'email' => $email_clean,    'hash'  => $hash    );$statement->execute($array_parameters);  }catch (Exception $error) {    echo Database error: . $error->getMessage();  }}
How do I put $db in a central location, but maintain variable scope
php;pdo