What are best practices for structuring INSERT INTO queries in PHP?

When structuring INSERT INTO queries in PHP, it is best practice to use prepared statements to prevent SQL injection attacks and ensure data integrity. Prepared statements separate the SQL query from the data input, making it safer and more efficient. Here is an example of how to structure an INSERT INTO query using prepared statements in PHP:

// Establish a database connection
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');

// Prepare the SQL query
$stmt = $pdo->prepare("INSERT INTO users (username, email) VALUES (:username, :email)");

// Bind parameters
$stmt->bindParam(':username', $username);
$stmt->bindParam(':email', $email);

// Set parameters and execute the query
$username = 'john_doe';
$email = 'john_doe@example.com';
$stmt->execute();