Reputation:
I try to create a table with CREATE TABLE IF NOT EXISTS
but something wrong. I couldn't solve that. Could anyone helps me?
<?php
$server = "localhost";
$user = "root";
$password = "";
$dbname = "bombus";
$connection = @new mysqli( $server, $user, $password, $dbname ) or die( "ERROR : " . mysqli_error() );
$tablename = "users";
$newTable = $connection->query("CREATE TABLE IF NOT EXISTS $tablename(
ID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(ID),
userName VARCHAR(MAX) NOT NULL UNIQUE,
password CHAR(32) NOT NULL,
isAdmin TINYINT(1) NOT NULL,
companyID int NOT NULL,
branchID int NOT NULL
)");
mysqli_close($connection);
?>
Thank you for your helps.
Upvotes: 0
Views: 596
Reputation: 16436
You have some issues in your script. change your create table query like below:
$newTable = $connection->query("CREATE TABLE IF NOT EXISTS $tablename(
ID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(ID),
userName VARCHAR(50) NOT NULL UNIQUE,
user_password CHAR(32) NOT NULL,
isAdmin TINYINT(1) NOT NULL,
companyID int NOT NULL,
branchID int NOT NULL)");
Upvotes: 1