I have seen some ways to connect to the MySQL DB with PHP, but don't know why the one is better than the other, or safer or anything. Same thing goes with inserting or fetching data to/from the database.
This is some examples of MYSQL connection with PHP:
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', 'password');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'test');
$db = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
OR die('Could not connect to database. '.mysqli_connect_error());
OR
class kobling extends mysqli {
public function __construct(
$host = "127.0.0.1",
$base = "test",
$user = "root",
$pw = "password",
$port = "3306") {
parent::__construct($host,$user,$pw,$base,$port);
}
}
if (!($db = new kobling())) {
die("Kunne ikke koble til databasen.");
}
Any suggestions or solutions?