Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z tworzeniem i (chyba) auto_increment
darth_sidious
post 6.01.2007, 23:47:00
Post #1





Grupa: Zarejestrowani
Postów: 66
Pomógł: 1
Dołączył: 19.12.2005

Ostrzeżenie: (0%)
-----


Witam

"Bawie" sie wlasnie skryptem typerow Prediction League i juz na samym poczatku, podczas instalacji i konfiguracji bazy (MySql) mam juz maly problem. Skrypt instalacyjny tworzy baze a nastepnie tabele potrzebne do dzialania skryptu. Baza tworzy sie bez problemu. Problem pojawil sie przy tworzeniu tabel. Z tego co zauwazylem z tabela, w ktorej primary key nie jest auto_increment nie ma problemu - tworzy sie. Lecz gdy primary key jest auto_increment pojawia sie nastepujacy error:

Query failed: create table pl.pluserdata (lid int not null , userid int not null auto_increment, username varchar(32) not null , password varchar(40), email varchar(60), icon varchar(128), lang varchar(32), usertype smallint, dflths smallint default 0, dfltas smallint default 0, since DATE, isauto enum('Y','N') default 'N', primary key (lid, userid));
Incorrect table definition; there can be only one auto column and it must be defined as a key


Ponizej kod, ktory tworzy tabele, ktorej blad widnieje powyzej:

  1. <?php
  2. $query = "create table $dbname.$dbaseUserData
  3. (lid int not null ,
  4.  userid int not null auto_increment,
  5.  username varchar($userlen) not null ,
  6.  password varchar($passlen),
  7.  email varchar($emaillen),
  8.  icon varchar($fnamelen),
  9.  lang varchar(32),
  10.  usertype smallint,
  11.  dflths smallint default 0,
  12.  dfltas smallint default 0,
  13.  since DATE,
  14.  isauto enum('Y','N') default 'N',
  15.  primary key (lid, userid));";
  16. $userresult = mysql_query($query)
  17. or die("Query failed: $query<br>n".mysql_error());
  18. ?>



A ponizej fragment, ktory nie wywala bleu i poprawnie tworzy tabele:

  1. <?php
  2. $query = "create table $dbname.$dbasePredictionData
  3.  (lid int not null ,
  4. userid int not null,
  5. matchid int not null,
  6. predtime timestamp,
  7. homescore smallint unsigned,
  8. awayscore smallint unsigned,
  9. isauto enum('Y','N') default 'N',
  10. primary key(lid, userid, matchid))";
  11. $userresult = mysql_query($query)
  12. or die("Query failed: $query<br>n".mysql_error());
  13. ?>


Co jest nie tak. Zaznaczam, ze nic sam nie kombinowale - jest to fragment oryginalnego skryptu tworzacego tabele...

Pozdrawiam
Darth


--------------------
Fotografia ślubna Tomaszów Mazowiecki
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 17)
nospor
post 7.01.2007, 11:19:19
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




no chyba wyraźnie ci napisalo:
Cytat
Incorrect table definition; there can be only one auto column and it must be defined as a key

to co jest autoincrementem musi byc kluczem glownym. u ciebie tak nie jest. ty tworzysz taki klucz glowny:(lid, userid)


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
darth_sidious
post 7.01.2007, 11:46:57
Post #3





Grupa: Zarejestrowani
Postów: 66
Pomógł: 1
Dołączył: 19.12.2005

Ostrzeżenie: (0%)
-----


Tzn, ze jesli ktores pole jest auto_increment to moze byc tylko 1 primary key?

Darth


--------------------
Fotografia ślubna Tomaszów Mazowiecki
Go to the top of the page
+Quote Post
nospor
post 7.01.2007, 11:48:27
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




tak. wkoncu autoincrement jednoznacznie definiuje rekord


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
darth_sidious
post 7.01.2007, 11:51:24
Post #5





Grupa: Zarejestrowani
Postów: 66
Pomógł: 1
Dołączył: 19.12.2005

Ostrzeżenie: (0%)
-----


No mam dylemat... Jak juz pisalem zmieniam oryginalny skrypt a tam wlasnie mimo auto_increment sa 2 primary key... Boje sie, ze jesli usune jednen z nich (w tym przypadku lid) cos przestanie dzialac... Czy jest na to jakas rada?


--------------------
Fotografia ślubna Tomaszów Mazowiecki
Go to the top of the page
+Quote Post
wipo
post 7.01.2007, 11:56:01
Post #6





Grupa: Zarejestrowani
Postów: 856
Pomógł: 19
Dołączył: 30.08.2005
Skąd: 100lica

Ostrzeżenie: (0%)
-----


Ale już Ci to napisał nospar że nie można w obrębie jednej tabeli uzyć 2 razy primary key.
Popatrz może na foreign key albo inne klucze

Tak pozatym dobrze byłoby skontaktowac się z autorem co chciał przez takie odwołanie uzyskać


--------------------
Go to the top of the page
+Quote Post
nospor
post 7.01.2007, 11:57:26
Post #7





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




wydaje mi sie troche dziwne robic klucz glowny z polaczenia autoincrement i innego pola.

To mowisz ze oni mieli tak sql? autoincrement i podwojny klucz? a pisali na jakiej bazce to ma chodzic i na jakiej wersji?

Nie wiem czy cos ci nie napsuje usuwania jednego klucza (dalej nie wiem jakim cudem im sie udalo zalozyc dwa - byc moze oczym nie wiem), wszystko zalezy jak oni tym zarządzają poźniej w skrypcie.

Cytat
nie można w obrębie jednej tabeli uzyć 2 razy primary key.
tego nie napisalem, czytaj uwaznie smile.gif (co nie zmienia faktu ze nie mozna, mozna za to raz ale na kilku polach, pod warunkiem ze nie ma autoincrement)


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
darth_sidious
post 7.01.2007, 12:13:20
Post #8





Grupa: Zarejestrowani
Postów: 66
Pomógł: 1
Dołączył: 19.12.2005

Ostrzeżenie: (0%)
-----


Skrypt powinien dzialac na php 4.0 lub nowszym i bazie MySql... przeszukiwalem rozne fora, ale nigdzie nie znalazlem informacji o tym aby ktos mial podobny problem do mojego z instalacja...
W instrukcji instalacji tegoz skryptu nie ma nawet mowy o jakichs problemach z baza i ingerencji w nia... Plik instalacyjny w pierwszej kolejnosci tworzy baze (to ok) a nastepnie tabele... te w ktorych nie ma autoincrement tworza sie bez problemu, te w ktorych jest -> wynik j/w...


--------------------
Fotografia ślubna Tomaszów Mazowiecki
Go to the top of the page
+Quote Post
nospor
post 7.01.2007, 12:17:01
Post #9





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Cytat
na php 4.0 lub nowszym i bazie MySql
mi wlasnie chodzilo o wersje mysql a nie php. php do bazy nie ma nic wspolnego.

zgodnie z komunikatem jaki dostajesz nie mozesz utworzyc kluacza podwojnego gdy masz autoincrement. wiec albo masz zla wersje bazy (oni robili to na innej), albo sie walneli w skrypcie sql


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
darth_sidious
post 7.01.2007, 12:23:20
Post #10





Grupa: Zarejestrowani
Postów: 66
Pomógł: 1
Dołączył: 19.12.2005

Ostrzeżenie: (0%)
-----


No wlasnie o wersji bazy nie ma mowy.... sadsmiley02.gif


--------------------
Fotografia ślubna Tomaszów Mazowiecki
Go to the top of the page
+Quote Post
wipo
post 7.01.2007, 12:30:01
Post #11





Grupa: Zarejestrowani
Postów: 856
Pomógł: 19
Dołączył: 30.08.2005
Skąd: 100lica

Ostrzeżenie: (0%)
-----


Nie jesteś pewnien jaka baza czy która wersja?


--------------------
Go to the top of the page
+Quote Post
darth_sidious
post 7.01.2007, 12:31:34
Post #12





Grupa: Zarejestrowani
Postów: 66
Pomógł: 1
Dołączył: 19.12.2005

Ostrzeżenie: (0%)
-----


Bazy jestem pewien - mysql... nie mam pewnosci co do obslugiwanej wersji....

Ten post edytował darth_sidious 7.01.2007, 12:33:34


--------------------
Fotografia ślubna Tomaszów Mazowiecki
Go to the top of the page
+Quote Post
nospor
post 7.01.2007, 12:41:34
Post #13





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




moze ty tworzysz tabele typu innoDB? bo znalazlem w manualu,ze dla MyISAM mozna tak tworzyc.
http://dev.mysql.com/doc/refman/5.1/en/exa...-increment.html
Cytat
For MyISAM tables you can specify AUTO_INCREMENT on a secondary column in a multiple-column index. In this case, the generated value for the AUTO_INCREMENT column is calculated as MAX(auto_increment_column) + 1 WHERE prefix=given-prefix. This is useful when you want to put data into ordered groups. CREATE TABLE animals ( grp ENUM('fish','mammal','bird') NOT NULL, id MEDIUMINT NOT NULL AUTO_INCREMENT, name CHAR(30) NOT NULL, PRIMARY KEY (grp,id) );


i jeszcze cos z komentow:
Kod
AUTO_INCREMENT on a secondary column in a multiple-column index:

Specify 'type=myisam' for the table if you want to avoid getting:
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key

Ref. script example from manual:
CREATE TABLE animals (
grp ENUM('fish','mammal','bird') NOT NULL,
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (grp,id)
);
Does not work if your default is not MyISAM, while the script below works fine:

CREATE TABLE animals (
grp ENUM('fish','mammal','bird') NOT NULL,
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (grp,id)
) type=myisam;


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
darth_sidious
post 7.01.2007, 12:51:47
Post #14





Grupa: Zarejestrowani
Postów: 66
Pomógł: 1
Dołączył: 19.12.2005

Ostrzeżenie: (0%)
-----


OK... przyjrze sie temu blizej... postaram sie cos pokombinowac i dam znac znac o efektach...


--------------------
Fotografia ślubna Tomaszów Mazowiecki
Go to the top of the page
+Quote Post
nospor
post 7.01.2007, 12:53:04
Post #15





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




ale co tu kombinowac? musisz dopisac na koniec sql: type=myisam; tak ja ci podalem w ostanim poscie z komentow.
Kod
<?php
$query = "create table $dbname.$dbaseUserData
            (lid int not null ,
             userid int not null auto_increment,
             username varchar($userlen) not null ,
             password varchar($passlen),
             email varchar($emaillen),
             icon varchar($fnamelen),
             lang varchar(32),
             usertype smallint,
             dflths smallint default 0,
             dfltas smallint default 0,
             since DATE,
             isauto enum('Y','N') default 'N',
             primary key (lid, userid)) type=myisam";
?>


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
darth_sidious
post 7.01.2007, 15:15:06
Post #16





Grupa: Zarejestrowani
Postów: 66
Pomógł: 1
Dołączył: 19.12.2005

Ostrzeżenie: (0%)
-----


Wielkie dzieki snitch.gif

Po dodaniu
  1. <?php
  2. type=myisam
  3. ?>

Wszystko dziala....

Jeszcze raz wszystkim Wam bardzo dziekuje za pomoc biggrin.gif

Pozdrawiam
Darth


--------------------
Fotografia ślubna Tomaszów Mazowiecki
Go to the top of the page
+Quote Post
jarek26
post 2.10.2010, 08:44:10
Post #17





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 2.10.2010
Skąd: Łomża

Ostrzeżenie: (0%)
-----


Witam. Mógłby mi ktokolwiek pomóc gdyż mam podobny problem z tym samym skryptem z tym, że jest to nowsza wersja. Po próbie tworzenia tabeli pokazuje się taki błąd
Kod
Query failed: create table fpgpl_typer.pluserdata (lid int not null , userid int not null auto_increment, username varchar(32) not null , password varchar(40), email varchar(60), icon varchar(128), lang varchar(32), usertype smallint, dflths smallint default 0, dfltas smallint default 0, since DATE, auto enum('Y','N') default 'N', primary key (lid,userid));
Incorrect table definition; there can be only one auto column and it must be defined as a key
czyli taki sam jak u osoby która rozpoczęła temat. Teoretycznie jest rozwiązanie lecz on miał inną wersję skryptu a ja mam inną. Moje pytanie brzmi. Gdzie dodać i czy wogóle dodawać wartość
  1.  
  2. <?php
  3. type=myisam
  4. ?>


jeżeli kod do tworzenia tabeli wygląda następująco
  1. if ($createtables == "TRUE") {
  2. $query = "create table $dbname.$dbaseUserData (lid int not null , userid int not null auto_increment, username varchar($userlen) not null , password varchar($passlen), email varchar($emaillen), icon varchar($fnamelen), lang varchar(32), usertype smallint, dflths smallint default 0, dfltas smallint default 0, since DATE, auto enum('Y','N') default 'N', primary key (lid,userid));";
  3. $userresult = mysql_query($query)
  4. or die("Query failed: $query<br>\n".mysql_error());
  5.  
  6.  
  7.  
  8. $query = "create table $dbname.$dbasePredictionData (lid int not null , userid int not null, matchid int not null ,predtime timestamp, homescore smallint unsigned, awayscore smallint unsigned, isauto enum('Y','N') default 'N', primary key(lid, userid, matchid))";
  9. $userresult = mysql_query($query)
  10. or die("Query failed: $query<br>\n".mysql_error());
  11.  
  12. $query = "create table $dbname.$dbaseMatchData (lid int not null, matchid int not null auto_increment, matchdate DATETIME not null, hometeam varchar($teamlen) not null, awayteam varchar($teamlen) not null, homescore smallint unsigned, awayscore smallint unsigned, primary key(lid,matchid));";
  13. $userresult = mysql_query($query)
  14. or die("Query failed: $query<br>\n".mysql_error());
  15.  
  16. $query = "create table $dbname.$dbaseStandings (lid int not null, userid int not null, position smallint not null, pld int unsigned, won int unsigned, drawn int unsigned, lost int unsigned, gfor smallint unsigned, gagainst smallint unsigned, diff smallint, points int unsigned, primary key(lid,userid));";
  17. $userresult = mysql_query($query)
  18. or die("Query failed: $query<br>\n".mysql_error());
  19.  
  20. $query = "create table $dbname.$dbaseConfigData (lid int not null, grp int not null, param varchar(32) not null, value varchar(90) not null, descr text not null, ro enum('Y','N') default 'N', primary key(lid,param));";
  21. $userresult = mysql_query($query)
  22. or die("Query failed: $query<br>\n".mysql_error());
  23.  
  24. $query = "create table $dbname.$dbaseMsgData (lid int not null, msgid int not null auto_increment, threadid int, prevmsg int, sender int not null, receiver int not null, subject varchar(255), body text, status enum(\"new\",\"read\",\"deleted\"), msgtime timestamp, primary key(lid,msgid));";
  25. $userresult = mysql_query($query)
  26. or die("Query failed: $query<br>\n".mysql_error());
  27.  
  28. }


Bardzo proszę o pomoc bo nie potrafię sę sam z tym poradzić. Z góry dziękuję za pomoc. Pozdrawiam
Go to the top of the page
+Quote Post
nospor
post 4.10.2010, 06:05:56
Post #18





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Przeciez masz wyraźnie napisane: Moze byc tylko jeden autoincrement i musi byc kluczem głównym.
A u ciebie klucz główny sklada sie z dwóch pol: (lid,userid), a jesli uzywasz autoincrement to moze skladac sie tylko z tego jednego pola.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 01:06