SA-MP Forums Archive
Mysql Statments - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Mysql Statments (/showthread.php?tid=576460)



Mysql Statments - nezo2001 - 04.06.2015

I know I'm asking alot, but it is MYSQL :P
Now for the statments, I wanna know what is the correct way to do:-

Delete - Insert - Update:
when should I add this (`)
should I add it with the values and fields' names (Insert Into `table` ("//here"Field's name"//here")VALUES ("//here "value"//here")
And same for others


Re: Mysql Statments - Luis- - 04.06.2015

Here's a snippet from my gamemode;
pawn Код:
"UPDATE `master_accounts` SET `Name`='%e',`Admin`=%d,`Email`='%e', `IP`='%e',`Warnings`=%d,`TotalChars`=%d WHERE `ID`=%d"
Should help you out a little.


Re: Mysql Statments - Konstantinos - 04.06.2015

All of them are correct ways. I personally don't use ` character around fields' and table's name, nor ' around integers/floats so the query will be shorter.

About the INSERT query, you could add only the values and not the fields' name but if you use default values (something which you should do) add the names (only those with no default values).


Re: Mysql Statments - dusk - 04.06.2015

The character '`' is used to distinguish mysql keywords from field/table names.

For example, the word "update" is a mysql keyword. You CAN NOT use it as a colum name unless you surround it with `.

Код:
CREATE TABLE IF NOT EXISTS example (
    `update` INT NOT NULL DEFAULT '0'
);
This would work, you would have a column named "update". But I'm sure this isn't common practice.


Re: Mysql Statments - nezo2001 - 05.06.2015

In another way, what is the correct way for this
PHP код:
mysql_format(1add,sizeof(add),"INSERT INTO users (pName, pPass, pMoney, pAdmin, pWarnings, pPolice, pGang, pHorseshoes, pScore, pDealer, pJob, pDay, pMonth, pYear) VALUES (%s, %i, 10000, 0, 0, 0, 0, 0, 0, 0, 0, %i, %i, %i",PlayerName(playerid), udb_hash(inputtext), DayMonthYear); 
Cuz when I debugged it I got an error.


Re: Mysql Statments - Konstantinos - 05.06.2015

Change to:
pawn Код:
"... VALUES ('%s', %i, ..."



Re: Mysql Statments - nezo2001 - 05.06.2015

Can you write the full statment cuz I can't understand this


Re: Mysql Statments - dusk - 05.06.2015

pawn Код:
mysql_format(1, add,sizeof(add),"INSERT INTO users (pName, pPass, pMoney, pAdmin, pWarnings, pPolice, pGang, pHorseshoes, pScore, pDealer, pJob, pDay, pMonth, pYear) VALUES ('%s', %i, 10000, 0, 0, 0, 0, 0, 0, 0, 0, %i, %i, %i",PlayerName(playerid), udb_hash(inputtext), Day, Month, Year);
In short, when ever you use %s, surround it with '. So it would be '%s'.


Re: Mysql Statments - nezo2001 - 05.06.2015

MySql log:
Код:
[12:51:53] [ERROR] CMySQLQuery::Execute - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
[12:51:53] [DEBUG] mysql_errno - connection: 1



Re: Mysql Statments - Konstantinos - 05.06.2015

There is also a missing closed parenthesis at the end of the query from VALUES (...)

The red one is missing, just add it after the last %i and before ".