MySQLi Procedural create Table frage

Loddar1

Erfahrenes Mitglied
Wenn ich meine Tabellen installieren will, geht das bisher so:
PHP:
<?php
$servername = "xxxxxx";
$username = "xxxxx";
$password = "xxxxxx";
$dbname = "xxxxxx";

$sql_link = mysqli_connect($servername, $username, $password, $dbname);
if (!$sql_link) {
die("Connection failed: " . mysqli_connect_error());
}

$sqlquerya = "CREATE TABLE `sites` (
  `mid` int(4) unsigned NOT NULL auto_increment,
  `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  `heading` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`mid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";

$sqlqueryb = "CREATE TABLE `meta` (
     `id` int(3) NOT NULL default '1',
     `descript` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
     `keyword` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
     PRIMARY KEY  (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
   
$sqlqueryc = "CREATE TABLE `impres` (
  `id` int(11) NOT NULL default '1',
  `vname` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
  `nname` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";

$sqlqueryd = "CREATE TABLE `news` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `titel` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
  `name` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";



if (mysqli_query($sql_link, $sqlquerya)) {
        echo "Table sites created successfully<br/>";
    }
    else
    {
    echo "Error creating table: " . mysqli_error($sql_link);
}

if (mysqli_query($sql_link, $sqlqueryb)) {
        echo "Table meta created successfully<br/>";
        }
        else
        {
    echo "Error creating table: " . mysqli_error($sql_link);
}

if (mysqli_query($sql_link, $sqlqueryc)) {
            echo "Table impres created successfully<br/>";
        }
        else
        {
    echo "Error creating table: " . mysqli_error($sql_link);
}
if (mysqli_query($sql_link, $sqlqueryd)) {
            echo "Table news created successfully<br/>";
        }
        else
        {
    echo "Error creating table: " . mysqli_error($sql_link);
}

mysqli_close($sql_link);
?>

Jetzt wollte ich es verkürzen und übersichtlicher machen,
aber da bekomme ich Fehler gemeldet:
irgendwas mit "default '1'" darf nicht sein.

Wenn ich meine Tabellen füllen will, dann geht die 2te option mit $ss .= xxx


PHP:
<?php
$servername = "xxxxxx";
$username = "xxxxx";
$password = "xxxxxx";
$dbname = "xxxxxx";

$sql_link = mysqli_connect($servername, $username, $password, $dbname);
if (!$sql_link) {
die("Connection failed: " . mysqli_connect_error());
}

$sqlquery = "CREATE TABLE `sites` (
  `mid` int(4) unsigned NOT NULL auto_increment,
  `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  `heading` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`mid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";

$sqlquery .= "CREATE TABLE `meta` (
     `id` int(3) NOT NULL default '1',
     `descript` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
     `keyword` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
     PRIMARY KEY  (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
   
$sqlquery .= "CREATE TABLE `impres` (
  `id` int(11) NOT NULL default '1',
  `vname` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
  `nname` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";

$sqlquery .= "CREATE TABLE `news` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `titel` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
  `name` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";


if (mysqli_query($sql_link, $sqlquery)) {
        echo "Tables created successfully<br/>";
    }
    else
    {
    echo "Error creating tables: " . mysqli_error($sql_link);
}

mysqli_close($sql_link);
?>

Sieht einer einen Fehler oder kann mir helfen?
Danke schonmal,
Die Tabellen sind verkürzt dargestellt.
 
Ich würde jetzt sagen, vllt weil du versucht einen String als Default Wert auf ein Integer Feld zu schreiben?!
Probier doch mal aus, die Hochkomma weg zu lassen?
 

Neue Beiträge

Zurück