PDA

View Full Version : MySQL


Tony$$
13/06/2015, 02:45 PM
Was creating a new column for my new system.
Anyways i filled all the sections except this one. I am not sure what it is.
http://gyazo.com/1bd2377f9a7947f2eab5dcaa15e91141
Index.
Should i set it as primary or what?
P.S. I might have posted in a wrong section. If so, sorry for that.

SKAzini
13/06/2015, 02:52 PM
If you have an ID field for example, setting that field as Primary will make it the identifier for the row. No other row will be able to have the same ID as another row, since it's the unique identifier for the row.

So, if the field you're trying to set index for is supposed to act like an unique identifier, set it as Primary.

Stanford
13/06/2015, 02:52 PM
If your column is a key ---> choose primary key (like an ID or whatever) else kept it empty if you want!

Konstantinos
13/06/2015, 02:53 PM
You should really consider reading more about SQL: https://dev.mysql.com/doc/refman/5.5/en/optimization-indexes.html

Tony$$
13/06/2015, 03:06 PM
Ahh i got it now. Thanks
ANyways i made a column. Whenever you write your email it supposed to insert into the E-Mail column which i just created but instead it just create a new section with the email only.
Here is the code:
SQL_SubmitEmail(playerid, string[]) // there should be a " , playerid) "
{
new
query[512],name[32];
GetPlayerName(playerid,name,sizeof(name));
// format(query, sizeof(query), "INSERT INTO `accounts` (`ID`, `E-Mail`) VALUES('%d', '%s')", PlayerData[playerid][pID], string);
format(query,sizeof(query), "INSERT INTO `accounts` (`ID`, `E-Mail`) VALUES('%d', '%s')", PlayerData[playerid][pID], string);
mysql_tquery(g_iHandle, query);
}

and here is a photo too
http://gyazo.com/adf69d119ca73ea62d16175783207447
Not sure if this code is needed too.
SQL_CreateAccount(const username[], const password[])
{
new
query[512],
buffer[129];

WP_Hash(buffer, sizeof(buffer), password);

format(query, sizeof(query), "INSERT INTO `accounts` (`Username`, `Password`, `RegisterDate`, `LoginDate`) VALUES('%s', '%s', '%s', '%s')", username, buffer, ReturnDate(), ReturnDate());
mysql_tquery(g_iHandle, query);
}

Konstantinos
13/06/2015, 03:12 PM
You already insert a new row so use UPDATE statement instead and set `E-Mail` field WHERE `ID` is known.

And have "ID" field PRIMARY KEY with AUTO INCREMENT.

Tony$$
13/06/2015, 03:44 PM
OKay i replaced it with UPDATE and ID field already has A_I and PRIMARY KEY
But now it wont even update the E-Mail field. It just stays null

format(query,sizeof(query), "UPDATE `accounts` (`ID`, `E-Mail`) WHERE (`ID`) VALUES('%d', '%s')", PlayerData[playerid][pID], string);

http://gyazo.com/82b107272525be2d04e2ee4221f22f12

Konstantinos
13/06/2015, 03:49 PM
The syntax is totally different - as I said before: read more about SQL: https://dev.mysql.com/doc/refman/5.0/en/update.html

and I'm pretty sure it's not A_I as it started from -1 when by default, they start from 1 (plus I see no reason you would have set another starting value to it).

Tony$$
13/06/2015, 04:22 PM
It is A_I
http://gyazo.com/bdccc1c4ecc539950e57eb221c91bf51