SQLite question
#1

Hello there! so i have started learning SQLite ways, but i got a little question about it,

For example i tried this first to test,

PHP код:
#include <a_samp>
#include <a_sampdb>
#include <zcmd>
main() { }
new 
DBsomeDB// Handle for database. Our queries need to use this so the queries know where to handle things
public OnGameModeInit() {
   
someDB db_open("your.db"); // file 'your.db' will be our SQLite database
}
CMD:getmyname(playeridparams[]) {
    new 
szQuery[74], szOut[32], DBResultqueryszPlayerName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridszPlayerNameMAX_PLAYER_NAME);
    
format(szQuerysizeof(szQuery), "select * from `players` where `playername` = '%s'"szPlayerName);
    
query db_query(someDBszQuery);
    if(
db_num_rows(query) > 0) {
        
SendClientMessage(playerid0"There is more than 0 rows, meaning there is at least 1 row!");
        
SendClientMessage(playerid0"So there is a registered account with my name!");
        
db_get_field_assoc(query"Motto"szOutsizeof(szOut));
        
SendClientMessage(playerid0"Your motto is:");
        
SendClientMessage(playerid0szOut);
        
db_free_result(query);
    }
    return 
1;

it's from a tutorial, i would know how to make a database in scriptfiles, for example like yourdb.dll, it got compiled gratefully but didn't show any file in scriptfiles, does it require player to join the server and use it and to be showen? thanks anyway!
Reply
#2

db_open native will automatically create the database if doesn't exist.
Reply
#3

As soon as the server will start, it will create the file which will be empty. Make sure scriptfiles have correct permissions.

Two more things: %q in format to escape strings and free the result at the very end (because it doesn't free the result if there are not any rows).
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
As soon as the server will start, it will create the file which will be empty. Make sure scriptfiles have correct permissions.

Two more things: %q in format to escape strings and free the result at the very end (because it doesn't free the result if there are not any rows).
Yea i have noticed that, thanks btw

Quote:
Originally Posted by PawnHunter
Посмотреть сообщение
db_open native will automatically create the database if doesn't exist.
Okay Thanks.
Reply
#5

Good to see you doing something finally (sarcastic facepalm :P)

I'd recommend you to read Sreyas' SQL introduction and some other good tutorials to know some basics. Best of luck in learning.
Reply
#6

He is.not.even responsible to do yini but this.... Nice try
Reply
#7

Quote:
Originally Posted by Hunud
Посмотреть сообщение
He is.not.even responsible to do yini but this.... Nice try
Thanks pro.

Quote:
Originally Posted by Logic_
Посмотреть сообщение
Good to see you doing something finally (sarcastic facepalm :P)

I'd recommend you to read Sreyas' SQL introduction and some other good tutorials to know some basics. Best of luck in learning.
Ok thank you.
Reply
#8

Nice decision moving to SQL, best of luck mate
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)