I'm trying to create a new table with this code:
try {
$db = new PDO("mysql:hostname=localhost",'root','root');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo $e->getMessage();
die();
}
//to create database
$db->query("CREATE DATABASE theShop IF NOT EXISTS ;");
$db->query("USE theShop;");
$createTableShops = "CREATE TABLE `advertisor`
(
`ShopID` UNSIGNED INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`ShopName` VARCHAR(50) NOT NULL,
)type=InnoDB;";
try {
$db->query($createTableShops);
} catch(PDOException $e) {
echo $e->getMessage();
}
at phpMyAdmin I browse for the database to make sure if it's actually have been created, I tried the code over and over but it always creates the database theShop but with 0(Zero) tables, why the table not created?
note: I've tried some changes:
- not using backtick
- changing the type of table
- changing the key word
type
toengine
- not using neither
type
norengine
- changing the connection string by adding
dbname=theShop
- many things ..!