Initially, create a table with name "users2", with five columns: "id","Username", "Password","First", "Last".
[sql]
CREATE TABLE users2 (
ID INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
Username varchar(20),
Password varchar(20),
First varchar(20),
Last varchar(20)
)[/sql]
Examples
(MySQLi Object-oriented)
[php]
<!DOCTYPE html>
<html>
<body>
<?php
$HostName = "localhost";
$UserName = "root";
$Password = "password";
$dbname="accounts";
// Create connection
$connection = new mysqli($HostName, $UserName, $Password, $dbname);
// Check connection
if ($connection->connect_error)
{
die("Connection failed: " . $connection->connect_error);
}
// sql to create table
$sql = "CREATE TABLE users2 (
ID INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
Username varchar(20),
Password varchar(20),
First varchar(20),
Last varchar(20)
)";
if ($connection->query($sql) === TRUE)
{
echo "Table users2 created successfully";
}
else
{
echo "Error creating table: " . $connection->error;
}
$connection->close();
?>
</body>
</html>
[/php]
The output in the phpmyadmin looks like below.