Jump to content

Create Table if not exists


ludo1960

Recommended Posts

I have the following code, The table 'TEST' is not created but the code reports "Table has been created" Any idea what is wrong?

<?php
 
$conn = mysqli_connect("localhost","myuser","mypassword","mydatabase");
 
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
 
$create_table = "CREATE TABLE IF NOT EXIST `TEST`
(
ID INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
County VARCHAR(50) NOT NULL,
Country VARCHAR(50) NOT NULL
)";
 
$create_tbl = $conn->query($create_table);
 
if ($create_table)
{
echo "Table has been created";
}
else
{
echo "error!!";
}
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.