PHP 8 - Connect PHP to MySQL

Last modified: April 02, 2022

MySQLi

DB Connection Information

<?php define("DB_HOST", "localhost"); define("DB_USERNAME", "demo"); define("DB_PASSWORD", "demo"); define("DB_DATABASE_NAME", "db");
<?php // Create connection $conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; ?>