How can data types be effectively assigned to database fields when creating tables in PHP?

When creating tables in a database using PHP, it is important to assign appropriate data types to each field to ensure data integrity and optimize storage. This can be achieved by specifying the data type for each column in the CREATE TABLE statement. Common data types include INT for integers, VARCHAR for variable-length strings, DATE for dates, and TEXT for large text fields.

// Create a table with specified data types for each field
$sql = "CREATE TABLE users (
    id INT(11) AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) NOT NULL,
    email VARCHAR(100) NOT NULL,
    birthdate DATE,
    bio TEXT
)";
mysqli_query($conn, $sql);