mysql table
#1

PHP код:
SetupPlayerTable()
{
    
mysql_tquery(g_SQL"CREATE TABLE IF NOT EXISTS `players` (`id` int(11) NOT NULL AUTO_INCREMENT,`username` varchar(24) NOT NULL,`password` char(64) NOT NULL,`salt` char(16) NOT NULL,`kills` mediumint(8) NOT NULL DEFAULT '0',`deaths` mediumint(8) NOT NULL DEFAULT '0',`respect`  mediumint(8) NOT NULL DEFAULT '0',`score`  mediumint(8) NOT NULL DEFAULT '0',`points`  mediumint(8) NOT NULL DEFAULT '0',`admin`  mediumint(8) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`))");
    return 
1;

Since the table is long, how do you make it to put more tables?
Reply
#2

PHP код:
SetupPlayerTable() 

    
mysql_tquery(g_SQL"CREATE TABLE IF NOT EXISTS `players` (`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(24) NOT NULL,
`password` char(64) NOT NULL,
`salt` char(16) NOT NULL,
`kills` mediumint(8) NOT NULL DEFAULT '0',
`deaths` mediumint(8) NOT NULL DEFAULT '0',
`respect`  mediumint(8) NOT NULL DEFAULT '0',
`score`  mediumint(8) NOT NULL DEFAULT '0',
`points`  mediumint(8) NOT NULL DEFAULT '0',
`admin`  mediumint(8) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`))"
); 
    return 
1

Also this are not tables but fields. Table players is a table.
You can create another table by this:
PHP код:
    mysql_tquery(g_SQL"CREATE TABLE IF NOT EXISTS `tablename` 
Reply
#3

Oh yeah, thanks.
Reply
#4

PHP код:
    mysql_tquery(g_SQL"CREATE TABLE IF NOT EXISTS `players` (`id` int(11) NOT NULL AUTO_INCREMENT,`username` varchar(24) NOT NULL,`password` char(64) NOT NULL,`salt` char(16) NOT NULL,`kills` mediumint(8) NOT NULL DEFAULT '0',`deaths` mediumint(8) NOT NULL DEFAULT '0',`respect`  mediumint(8) NOT NULL DEFAULT '0',`score`  mediumint(8) NOT NULL DEFAULT '0',`points`  mediumint(8) NOT NULL DEFAULT '0',`admin`  mediumint(8) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`))");
    
mysql_tquery(g_SQL"CREATE TABLE IF NOT EXISTS `players` (`duelswin`  mediumint(8) NOT NULL DEFAULT '0',`duelslost`  mediumint(8) NOT NULL DEFAULT '0')"); 
did what u said, but the second tquery doesnt add the 2 fields i wanted, duelswin and duelslost fields are not shown
Reply
#5

If you wanted to add more fields into the table you would just simply add this into the SQL;

Код:
`field_name` int(11) NOT NULL,
Jasperschellekens was correct, you were attempting to add more fields into a table that already exists. (excuting the 2nd SQL)

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
PHP код:
SetupPlayerTable() 

    
mysql_tquery(g_SQL"CREATE TABLE IF NOT EXISTS `players` (`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(24) NOT NULL,
`password` char(64) NOT NULL,
`salt` char(16) NOT NULL,
`kills` mediumint(8) NOT NULL DEFAULT '0',
`deaths` mediumint(8) NOT NULL DEFAULT '0',
`respect`  mediumint(8) NOT NULL DEFAULT '0',
`score`  mediumint(8) NOT NULL DEFAULT '0',
`points`  mediumint(8) NOT NULL DEFAULT '0',
`admin`  mediumint(8) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`))"
); 
    return 
1

Also this are not tables but fields. Table players is a table.
You can create another table by this:
PHP код:
    mysql_tquery(g_SQL"CREATE TABLE IF NOT EXISTS `tablename` 
Reply
#6

@jasperschellekens



The code is not reachable.

Код:
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3086) : error 037: invalid string (possibly non-terminated string)
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3086) : error 017: undefined symbol "CREATE"
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3086) : error 017: undefined symbol "TABLE"
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3086) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
That's why i tried adding a second query, it simply doesnt allow me to add on that one.
Reply
#7

You need to place a backslash(\) at end of each line included in the string in pawno. So the code becomes this:
PHP код:
mysql_tquery(g_SQL"CREATE TABLE IF NOT EXISTS `players` (`id` int(11) NOT NULL AUTO_INCREMENT, \
`username` varchar(24) NOT NULL, \
`password` char(64) NOT NULL, \
`salt` char(16) NOT NULL, \
`kills` mediumint(8) NOT NULL DEFAULT '0', \
`deaths` mediumint(8) NOT NULL DEFAULT '0', \
`respect`  mediumint(8) NOT NULL DEFAULT '0', \
... 
Reply
#8

PHP код:
SetupPlayerTable()
{
    
mysql_tquery(g_SQL"CREATE TABLE IF NOT EXISTS `players` (`id` int(11) NOT NULL AUTO_INCREMENT, \
    `username` varchar(24) NOT NULL,\
    `password` char(64) NOT NULL, \
    `salt` char(16) NOT NULL, \
    `kills` mediumint(8) NOT NULL DEFAULT '0', \
    `deaths` mediumint(8) NOT NULL DEFAULT '0', \
    `respect`  mediumint(8) NOT NULL DEFAULT '0', \
    `score`  mediumint(8) NOT NULL DEFAULT '0', \
    `points`  mediumint(8) NOT NULL DEFAULT '0', \
    `admin`  mediumint(8) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`))"
);
    return 
1;

Код:
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3094) : error 075: input line too long (after substitutions)
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3095) : error 037: invalid string (possibly non-terminated string)
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3095) : error 017: undefined symbol "CREATE"
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3095) : error 017: undefined symbol "TABLE"
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3095) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


5 Errors.
3094
PHP код:
`points`  mediumint(8NOT NULL DEFAULT '0', \ 
3095

PHP код:
`admin`  mediumint(8NOT NULL DEFAULT '0'PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`))"); 
Reply
#9

The query is too long. You can break the query into multiple parts and join them using strcat() like this:
PHP код:
new query[600] = "CREATE TABLE IF NOT EXISTS `players` (`id` int(11) NOT NULL AUTO_INCREMENT, \ 
    `username` varchar(24) NOT NULL,\ 
    `password` char(64) NOT NULL, \ 
    `salt` char(16) NOT NULL,"
;
strcat(query"`kills` mediumint(8) NOT NULL DEFAULT '0', \ 
    `deaths` mediumint(8) NOT NULL DEFAULT '0', \ 
    `respect`  mediumint(8) NOT NULL DEFAULT '0', \ 
    `score`  mediumint(8) NOT NULL DEFAULT '0',"
);
strcat(query"`points`  mediumint(8) NOT NULL DEFAULT '0', \ 
    `admin` mediumint(8) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY (`username`))"
);
mysql_tquery(g_SQLquery); 
If the line is still too long, you need to break the query into more parts.
Reply
#10

Yeah works thanks, but now that i need these 2 extra fields "duelswin" "duelslost", so basically thats my code

PHP код:
SetupPlayerTable()
{
    new 
query[1500];
    
strcat(query" CREATE TABLE IF NOT EXISTS `players` (`id` int(11) NOT NULL AUTO_INCREMENT, \
    `username` varchar(24) NOT NULL,\
    `password` char(64) NOT NULL, \
    `salt` char(16) NOT NULL, \
      `kills` mediumint(8) NOT NULL DEFAULT '0', \
    `deaths` mediumint(8) NOT NULL DEFAULT '0', \
    `respect`  mediumint(8) NOT NULL DEFAULT '0', \
    `score`  mediumint(8) NOT NULL DEFAULT '0',\
    `duelsw`  mediumint(8) NOT NULL DEFAULT '0',\
    `duelsl`  mediumint(8) NOT NULL DEFAULT '0',\
     `points`  mediumint(8) NOT NULL DEFAULT '0', \
    `admin` mediumint(8) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY (`username`))"
);

    
mysql_tquery(g_SQLquery);
    return 
1;

Код:
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3097) : error 075: input line too long (after substitutions)
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3098) : error 037: invalid string (possibly non-terminated string)
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3098) : error 017: undefined symbol "CREATE"
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3098) : error 017: undefined symbol "TABLE"
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3098) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


5 Errors.
But if i remove these 2 extra fields it's all ok, but since i need em both there, i guess i can't?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)