What are the potential security risks of not including username and password in a MySQL connection in PHP code?
If username and password are not included in a MySQL connection in PHP code, it can pose a serious security risk as anyone can access and manipulate the database without authentication. To solve this issue, always include the username and password in the connection string to ensure secure access to the database.
<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>