MySQL uses the CREATE TABLE command to create a table.
For example, create a table users, It will have three columns: id, name and age:
CREATE TABLE Users (id INTEGER AUTO_INCREMENT PRIMARY KEY, name VARCHAR(30), age INTEGER);
Full OOP example:
//Connect to DB $conn = new mysqli("localhost", "root", "password", "testdb"); //Check connection errors if($conn->connect_error){ die("Connection error: " . $conn->connect_error); } //Creating table $sql = "CREATE TABLE Users (id INTEGER AUTO_INCREMENT PRIMARY KEY, name VARCHAR(30), age INTEGER);"; //Check errors if($conn->query($sql)){ echo "Table crated"; } else{ echo "Error: " . $conn->error; } $conn->close();
Create MySQL database on PHP. OOP example
May 4, 2022