Skip to content
Advertisement

Setting up a web application using MySQL

I’m new to setting up a web based application. I have a server with MySQL setup with a database. The site is running my login web page. Currently I have users setup using MyPhpAdmin which will quickly prove burdensome. More importantly, once I run the command "$connection = mysqli_connect('1.2.3.4', $username, $password, 'databasename');", the variable $connection does not continue to exist on other PHP scripts even though I set it as global and tried " $GLOBALS['connection'] = $connection;".

Is there a standard practice to login with a single account for the PHP code and then manage the users with a database table? I’m a little leery of that approach for security reasons.

Advertisement

Answer

I think you misunderstand the $_GLOBALS. once you declared a variable outside a function or a class, it is already registered globally.

<?php


$foo = "bar";

function foo(){
    global $foo;
    echo $foo;
}

echo $_GLOBALS["foo"]; // Output: bar
foo(); // Output: bar
  • you can read more about PHP GLOBALS here.
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement