I need to create a class for connection to the DB. I know that hardcoding DB info is bad such as:
$user = "xxx";
$password = "yyy";
$server = "zzz";
$dbname = "name";
mysql_connect($user,$password,$server);
mysql_select_db($dbname);
That’s why i use “include” such as:
include "config.php"
which contains all the needed variables, and then I can use mysql_connect with them. But as far as i know, this is a bad practice as well. How can I use the mysqli class (extending it?) the easiest way, and ofcourse the safest possible?
Thanks for any tip
All the proposed answers could be correct I guess, but for my purpose and circumstances, i created a file that includes mysqli object creation and connection to DB with some functions for escaping data. Than I just include the file in all other .php’s that need DB connections and it’s very easy to use and execute queries. If someone needs more info or examples let me know.
Thanks to all