Latest MySQL version
#1

I recently decided to switch scripting database saving system from INI to MySQL, I installed MySQL R39-4 and worked fine with me of loading and saving data. Should i install another version of MySQL because i am new using it?

How to delete a row in this version?
I saw people using mysql_query("DELETE FROM ...") to delete, but this function is undefined in MySQL R39-4, so how to delete ?
Reply
#2

Код:
mysql_query(connection handle,"DELETE FROM `tabel` WHERE `whattofind:d` = 'whatisit[string/numeric]'");
example:
PHP код:
mysql_query(connection handle,"DELETE FROM `accounts` WHERE `Name` = '%s'",pName(playerid)); 
Reply
#3

It's mysql_tquery (or mysql_pquery, It moves each of your queries into a thread so it might break your code since stuff won't happen in the order you did them so if you want to use pquery use with caution) in R39-4 (threaded version of the same function), and your query is right, you should use "DELETE ..."
Reply
#4

What about the version? should i install another version or not ?
Reply
#5

Use the latest version; R39-4. You also have to escape strings to avoid exploits. The example of jlalt is wrong.
MySQL +R33 wiki page: https://sampwiki.blast.hk/wiki/MySQL/R33

mysql_format and mysql_tquery are key.
Reply
#6

MySQL quits creating new rows when a new player register, what's the reason?
I started a new blank page of pawn to detect what is causing the problem and i didn't figure it out!

Here is the script of registering dialog:
PHP код:
case DIALOG_REGISTER:
{
    if(!
response) return Kick(playerid);
    new 
day,month,year,ip[16],date[11]; GetPlayerIp(playeridipsizeof(ip)); getdate(year,month,day);
    
format(datesizeof(date), "%i/%i/%i",  daymonthyear);
    
mysql_format(ConnectionHandlequerysizeof(query), "INSERT INTO accounts (username, password, registerdate, ip) VALUES ('%s','%s','%s','%s')"GetName(playerid), inputtextdateip);
    
mysql_format(ConnectionHandlequerysizeof(query), "SELECT * FROM accounts WHERE username = '%s' LIMIT 1"GetName(playerid));
    
mysql_tquery(ConnectionHandlequery"LoadUserData""i"playerid);
    
format(stringsizeof(string), "{FFFFFF}Account Has Been Registered Successflly\n\n{E8E654}Account: {FFFFFF}%s\n\nType Your Password Below To Login."GetName(playerid));
    
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD,"{F03A3A}Juvanii's Cops And Robbers",string,"Login","Quit");
    return 
1;

LoadUserData Callback:
PHP код:
forward LoadUserData(playerid);
public 
LoadUserData(playerid)
{
    new 
rowsfields;
    
cache_get_data(rowsfieldsConnectionHandle);
    
printf("rows: %d | fields: %d"rowsfields);
    if(
rows)
    {
        
cache_get_field_content(0"password"PlayerInfo[playerid][Password], ConnectionHandle64);
        
cache_get_field_content(0"registerdate"PlayerInfo[playerid][RegisterDate], ConnectionHandle11);
        
cache_get_field_content(0"ip"PlayerInfo[playerid][IP], ConnectionHandle16);
        
PlayerInfo[playerid][Money] = cache_get_field_content_int(0"money");
        
PlayerInfo[playerid][Score] = cache_get_field_content_int(0"score");
        
PlayerInfo[playerid][Warrents] = cache_get_field_content_int(0"warrents");
        
PlayerInfo[playerid][RegularPlayer] = cache_get_field_content_int(0"regularplayer");
     }
    return 
1;

debug returns 0 rows and 8 fields, it's okay for the fields but why 0 rows ?


MySQL Log when a player join:
Код:
[01:34:34] [DEBUG] mysql_format - connection: 1, len: 128, format: "SELECT * FROM `accounts` WHERE `username` = '%e' LIMIT 1"
[01:34:34] [DEBUG] mysql_tquery - connection: 1, query: "SELECT * FROM `accounts` WHERE `username` = 'Juvanii' LIMIT 1", callback: "AccountChecking", format: "i"
[01:34:34] [DEBUG] CMySQLQuery::Execute[AccountChecking] - starting query execution
[01:34:34] [DEBUG] CMySQLQuery::Execute[AccountChecking] - query was successfully executed within 0.964 milliseconds
[01:34:34] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[01:34:34] [DEBUG] Calling callback "AccountChecking"..
[01:34:34] [DEBUG] cache_get_data - connection: 1
[01:34:34] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
MySQL Log when a player register:
Код:
[01:34:55] [DEBUG] mysql_format - connection: 1, len: 128, format: "INSERT INTO accounts (username, password, registerdate, ip) VALUES ('%s','%s','%s','%s')"
[01:34:55] [DEBUG] mysql_format - connection: 1, len: 128, format: "SELECT * FROM accounts WHERE username = '%s' LIMIT 1"
[01:34:55] [DEBUG] mysql_tquery - connection: 1, query: "SELECT * FROM accounts WHERE username = 'Juvanii' LIMIT 1", callback: "LoadUserData", format: "i"
[01:34:55] [DEBUG] CMySQLQuery::Execute[LoadUserData] - starting query execution
[01:34:55] [DEBUG] CMySQLQuery::Execute[LoadUserData] - query was successfully executed within 0.340 milliseconds
[01:34:55] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[01:34:55] [DEBUG] Calling callback "LoadUserData"..
[01:34:55] [DEBUG] cache_get_data - connection: 1
[01:34:55] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
Any help ?
Reply
#7

Escape your strings in mysql_format to avoid exploits! (Use the %e specifier).
Secondly, you should NEVER store passwords in plain text! Hash them and put a salt on them. I hereby refuse to help you until you secure the passwords.
Reply
#8

Quote:
Originally Posted by AndySedeyn
Посмотреть сообщение
Escape your strings in mysql_format to avoid exploits! (Use the %e specifier).
Secondly, you should NEVER store passwords in plain text! Hash them and put a salt on them. I hereby refuse to help you until you secure the passwords.
I was hashing it when i was using INI, i recently switched to MySQL from 2 days only so i kinda don't know everything about it plus this is not the final script, it will be changed after everything works fine, it's just me join the server and no one else. Anyway here what it looks like after hashing:

PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
DIALOG_REGISTER:
        {
            if(!
response) return Kick(playerid);
               new 
day,month,year,ip[16],date[11]; GetPlayerIp(playeridipsizeof(ip)); getdate(year,month,day);
               
format(datesizeof(date), "%i/%i/%i",  daymonthyear);
            
mysql_format(ConnectionHandlequerysizeof(query), "INSERT INTO accounts (username, password, registerdate, ip) VALUES ('%e','%i','%e','%e')"GetName(playerid), udb_hash(inputtext), dateip);
            
mysql_format(ConnectionHandlequerysizeof(query), "SELECT * FROM accounts WHERE username = '%e' LIMIT 1"GetName(playerid));
            
mysql_tquery(ConnectionHandlequery"LoadUserData""i"playerid);
            
format(stringsizeof(string), "{FFFFFF}Account Has Been Registered Successflly\n\n{E8E654}Account: {FFFFFF}%s\n\nType Your Password Below To Login."GetName(playerid));
            
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD,"{F03A3A}Juvanii's Cops And Robbers",string,"Login","Quit");
            return 
1;
        }
    }
    return 
1;
}
forward LoadUserData(playerid);
public 
LoadUserData(playerid)
{
    new 
rowsfields;
    
cache_get_data(rowsfieldsConnectionHandle);
    
printf("rows: %d | fields: %d"rowsfields);
    if(
rows)
    {
        
cache_get_field_content(0"registerdate"PlayerInfo[playerid][RegisterDate], ConnectionHandle11);
        
cache_get_field_content(0"ip"PlayerInfo[playerid][IP], ConnectionHandle16);
        
PlayerInfo[playerid][Password] = cache_get_field_content_int(0"password");
         
PlayerInfo[playerid][Money] = cache_get_field_content_int(0"money");
         
PlayerInfo[playerid][Score] = cache_get_field_content_int(0"score");
         
PlayerInfo[playerid][Warrents] = cache_get_field_content_int(0"warrents");
        
PlayerInfo[playerid][RegularPlayer] = cache_get_field_content_int(0"regularplayer");
     }
    return 
1;
}
stock udb_hash(buf[])
{
    new 
length=strlen(buf), s1 1s2 0n;
    for(
n=0n<lengthn++)
    {
       
s1 = (s1 buf[n]) % 65521;
       
s2 = (s2 s1)     % 65521;
    }
    return (
s2 << 16) + s1;

Reply
#9

You can reverse the algorithm used for udb_hash in the blink of an eye. Use something more secure (Whirlpool, MD5 or SHA256).

- Only string values should be between single quotation marks.
- You first format a query but you don't send it.
PHP код:
    mysql_format(ConnectionHandlequerysizeof(query), "INSERT INTO accounts (username, password, registerdate, ip) VALUES ('%e', %i,'%e','%e')"GetName(playerid), udb_hash(inputtext), dateip);
    
mysql_tquery(ConnectionHandlequery"""");
    
mysql_format(ConnectionHandlequerysizeof(query), "SELECT * FROM accounts WHERE username = '%e' LIMIT 1"GetName(playerid));
    
mysql_tquery(ConnectionHandlequery"LoadUserData""i"playerid); 
Read this tutorial: https://sampforum.blast.hk/showthread.php?tid=574714
Reply
#10

Quote:
Originally Posted by AndySedeyn
Посмотреть сообщение
You can reverse the algorithm used for udb_hash in the blink of an eye. Use something more secure (Whirlpool, MD5 or SHA256).

- Only string values should be between single quotation marks.
- You first format a query but you don't send it.
PHP код:
    mysql_format(ConnectionHandlequerysizeof(query), "INSERT INTO accounts (username, password, registerdate, ip) VALUES ('%e', %i,'%e','%e')"GetName(playerid), udb_hash(inputtext), dateip);
    
mysql_tquery(ConnectionHandlequery"""");
    
mysql_format(ConnectionHandlequerysizeof(query), "SELECT * FROM accounts WHERE username = '%e' LIMIT 1"GetName(playerid));
    
mysql_tquery(ConnectionHandlequery"LoadUserData""i"playerid); 
Read this tutorial: https://sampforum.blast.hk/showthread.php?tid=574714
I thought one mysql_tquery will send the both formats. Anyway, it worked fine! Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)