01.11.2015, 13:22
There are most definitely better ways to do this. In any case the database credentials should definitely not be global, nor should they be repeated in every file. Database error messages should not be sent directly to the output (unless for debugging) as these can contain sensitive information that an attacker may exploit.
I would recommend using a framework. We use CodeIgniter in class and I quite like the way it works. Configure the database settings and autoload the database driver. Very, very simple.
Takes a bit of getting used to, but you'll come to love it. There's plenty of documentation available.
I would recommend using a framework. We use CodeIgniter in class and I quite like the way it works. Configure the database settings and autoload the database driver. Very, very simple.
PHP код:
$this->db->where('username', $username);
$query = $this->db->get('player');
$player = $query->row();
echo $player->username;
echo $player->money;