What are the consequences of not following database normalization rules when storing data in PHP?

Not following database normalization rules when storing data in PHP can lead to data redundancy, inconsistency, and inefficiency in querying and updating data. To solve this issue, it is important to structure the database tables according to normalization principles, such as breaking down tables into smaller, related entities and avoiding repeating groups of data.

// Example of creating normalized tables in PHP using PDO

// Connect to the database
$dsn = 'mysql:host=localhost;dbname=mydatabase';
$username = 'username';
$password = 'password';
$pdo = new PDO($dsn, $username, $password);

// Create users table
$pdo->exec("CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) NOT NULL,
    email VARCHAR(100) NOT NULL
)");

// Create posts table
$pdo->exec("CREATE TABLE posts (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT,
    title VARCHAR(100) NOT NULL,
    content TEXT,
    FOREIGN KEY (user_id) REFERENCES users(id)
)");