PHP Basic Tutorial
MySQL Connection
Creating a table in MySQL using PHP involves writing a script to establish a database connection and executing a SQL CREATE TABLE query.
A database table has its own unique name and consists of columns and rows.
We will create a table named "users", with five columns: "id", "name", "email" and "created_at":
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Data types are used to specify the type of data that can be stored in a table's column.
You can specify other optional attributes for each column, followed by data type.
UNSIGNED
: Ensures the value is positive.AUTO_INCREMENT
: Automatically increments for each new row.PRIMARY KEY
: Makes id
the unique identifier for each record.NOT NULL
: Ensures the field cannot be empty.UNIQUE
: Ensures no duplicate email addresses.DEFAULT CURRENT_TIMESTAMP
: Automatically sets the current timestamp when a record is created.