MYSQL: mysql_fetch_field_row issue.
#1

Sup.

I've been working with Y_INI for months now and I've decided I want to start learning MySQL.

I was looking at tutorials last night and decided I'll restart a blank gamemode just so I can test using MySQL.

Can anyone notice whats wrong here?

It works properly if I use sscanf but with this method, it doesn't seem to work.

pawn Код:
new query[600],loadstr[20],pName[MPN];
GetPlayerName(playerid,pName,MPN);
format(query,sizeof(query),"SELECT * FROM accounts WHERE Name = '%s'",pName);

mysql_query(query);
mysql_store_result();

while(mysql_fetch_row_format(query,"|"))
{
    //sscanf(query,"p<|>ds[24]s[129]",AccountInfo[playerid][Id],AccountInfo[playerid][Name],AccountInfo[playerid][Password]); <-- I decided to test it with sscanf and it worked properly.
    mysql_fetch_field_row(loadstr,"ID");  AccountInfo[playerid][Id] = strval(loadstr);
    //^ works properly aswell, I printed out the ID and it's correct.
        //The last debug print shows here.
    mysql_fetch_field_row(AccountInfo[playerid][Name],"Name"); //<-- Crashes here.
    mysql_fetch_field_row(AccountInfo[playerid][Password],"Password");
}

mysql_free_result();
Here's the MySQL debugging information gathered.
Код:
[16:53:19] >> mysql_query( Connection handle: 1 )
[16:53:19] CMySQLHandler::Query(SELECT * FROM accounts WHERE name = 'Alonso_Moreno') - Successfully executed.
[16:53:19] >> mysql_store_result( Connection handle: 1 )
[16:53:19] CMySQLHandler::StoreResult() - Result was stored.
[16:53:19] >> mysql_num_rows( Connection handle: 1 )
[16:53:19] CMySQLHandler::NumRows() - Returned 1 row(s)
[16:53:22] >> mysql_query( Connection handle: 1 )
[16:53:22] CMySQLHandler::Query(SELECT * FROM accounts WHERE Name = 'Alonso_Moreno' AND Password = '000848C01650C0BC877F49A29F45A1AF342A7521E7EEE3B4960DF61AA5739085FD8CF38C22AA4F63E48E289134C822D521CBF9E5B75AD1D96C1C43F8B474CC24') - Successfully executed.
[16:53:22] >> mysql_store_result( Connection handle: 1 )
[16:53:22] CMySQLHandler::StoreResult() - Result was stored.
[16:53:22] >> mysql_num_rows( Connection handle: 1 )
[16:53:22] CMySQLHandler::NumRows() - Returned 1 row(s)
[16:53:22] >> mysql_query( Connection handle: 1 )
[16:53:22] CMySQLHandler::Query(SELECT * FROM accounts WHERE Name = 'Alonso_Moreno') - Successfully executed.
[16:53:22] >> mysql_store_result( Connection handle: 1 )
[16:53:22] CMySQLHandler::StoreResult() - Result was stored.
[16:53:22] >> mysql_retrieve_row( Connection handle: 1 )
[16:53:22] >> mysql_fetch_field_row( Connection handle: 1 )
[16:53:22] CMySQLHandler::FetchField("ID") - 8
[16:53:22] >> mysql_fetch_field_row( Connection handle: 1 )
Reply
#2

Well using sscanf is better because it's faster, it doesn't need any converting such as strval, floatstr and those stuff, also you should begin with the latest version, what's the point of learning the oldest version? well I suggest you learn ORM - Object-Relational Mapping.

Useful Links:

https://sampforum.blast.hk/showthread.php?tid=461766
https://sampforum.blast.hk/showthread.php?tid=493138
https://sampwiki.blast.hk/wiki/MySQL/R33
Reply
#3

Quote:
Originally Posted by Patrick_
Посмотреть сообщение
Well using sscanf is better because it's faster, it doesn't need any converting such as strval, floatstr and those stuff, also you should begin with the latest version, what's the point of learning the oldest version? well I suggest you learn ORM - Object-Relational Mapping.

Useful Links:

https://sampforum.blast.hk/showthread.php?tid=461766
https://sampforum.blast.hk/showthread.php?tid=493138
https://sampwiki.blast.hk/wiki/MySQL/R33
Okay, thanks for the information and links

I'll start looking at the tutorials now.

I always learn the latest version but I read somewhere that you shouldn't use R7+ if you don't understand how threading works as it only supports threaded queries.
Quote:

NOTE: DON'T USE VERSION R7 OR ABOVE IF YOU HAVE NO IDEA WHAT THREADING MEANS OR HOW IT WORKS. YOU MIGHT HARM YOUR SERVER WHEN USING IT NOT PROPERLY.

Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)