Mysql Statments
#1

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
Reply
#2

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.
Reply
#3

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).
Reply
#4

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.
Reply
#5

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.
Reply
#6

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

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

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'.
Reply
#9

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
Reply
#10

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 ".
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)