Raised This Month: $ Target: $400
 0% 

MqSql


Post New Thread Reply   
 
Thread Tools Display Modes
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-07-2010 , 21:29   Re: MqSql
Reply With Quote #11

I realized I made a mistake.

Change
Code:
if( SQL_NumResults( hQuery ) )
to
Code:
if( SQL_ReadResult( hQuery, 0 ) > 0 )
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
NzGamers
Member
Join Date: Jul 2009
Old 10-07-2010 , 21:33   Re: MqSql
Reply With Quote #12

is my Mysql init right?

PHP Code:
public MySql_Init()
{
    
g_hSqlTuple SQL_MakeDbTuple(g_Hostg_Userg_Passg_Db);
   
    new 
ErrorCodeHandle:SqlConnection SQL_Connect(g_hSqlTupleErrorCodeg_Errorcharsmax(g_Error));
    
    if(
SqlConnection == Empty_Handle)
        
set_fail_state(g_Error);
    
    new 
Handle:Queries;
    
Queries SQL_PrepareQuery(SqlConnection"CREATE TABLE IF NOT EXISTS users (username varchar(32),password varchar(32))");

    if(!
SQL_Execute(Queries))
    {
        
SQL_QueryError(Queriesg_Errorcharsmax(g_Error));
        
set_fail_state(g_Error);
       
    }
    
    
SQL_FreeHandle(Queries);
    
SQL_FreeHandle(SqlConnection); 

NzGamers is offline
shuttle_wave
Veteran Member
Join Date: Apr 2009
Location: New Zealand
Old 10-07-2010 , 22:26   Re: MqSql
Reply With Quote #13

Quote:
Originally Posted by NzGamers View Post
is my Mysql init right?

PHP Code:
public MySql_Init()
{
    
g_hSqlTuple SQL_MakeDbTuple(g_Hostg_Userg_Passg_Db);
   
    new 
ErrorCodeHandle:SqlConnection SQL_Connect(g_hSqlTupleErrorCodeg_Errorcharsmax(g_Error));
    
    if(
SqlConnection == Empty_Handle)
        
set_fail_state(g_Error);
    
    new 
Handle:Queries;
    
Queries SQL_PrepareQuery(SqlConnection"CREATE TABLE IF NOT EXISTS users (username varchar(32),password varchar(32))");

    if(!
SQL_Execute(Queries))
    {
        
SQL_QueryError(Queriesg_Errorcharsmax(g_Error));
        
set_fail_state(g_Error);
       
    }
    
    
SQL_FreeHandle(Queries);
    
SQL_FreeHandle(SqlConnection); 

yep that looks about right.
__________________
JailBreak Mod with Plugin API ( 90% ) Public
shuttle_wave is offline
FiFiX
Senior Member
Join Date: May 2008
Location: Poland
Old 10-08-2010 , 11:15   Re: MqSql
Reply With Quote #14

Quote:
Originally Posted by Exolent[jNr] View Post
You will need to change the queries to match your table.

Unthreaded:
Code:
CheckLogin( iPlayer, const szUserName[ ], const szPassword[ ] ) { new iError, szError[ 128 ]; new Handle:hDb = SQL_Connect( g_hSqlTuple, iError, szError, charsmax( szError ) ); if( hDb != Empty_Handle ) { new Handle:hQuery = SQL_PrepareQuery( hDb, "SELECT COUNT(*) FROM users WHERE username = ^"%s^" AND password = ^"%s^";", szUserName, szPassword ); if( !SQL_Execute( hQuery ) ) { SQL_QueryError( hQuery, szError, charsmax( szError ) ); log_amx( "Error checking login: %s", szError ); } else if( SQL_ReadResult( hQuery, 0 ) > 0 ) { client_print( iPlayer, print_chat, "* Successfully logged in!" ); } else { client_print( iPlayer, print_chat, "* Login failed!" ); } SQL_FreeHandle( hQuery ); SQL_FreeHandle( hDb ); } else { log_amx( "Error connecting to SQL: %s", szError ); } }


Threaded: Code:
CheckLogin( iPlayer, const szUserName[ ], const szPassword[ ] ) { new szQuery[ 128 ]; formatex( szQuery, charsmax( szQuery ), "SELECT COUNT(*) FROM users WHERE username = ^"%s^" AND password = ^"%s^";", szUserName, szPassword ); new iData[ 1 ]; iData[ 0 ] = iPlayer; SQL_ThreadQuery( g_hSqlTuple, "QueryCheckLogin", szQuery, iData, sizeof( iData ) ); } public QueryCheckLogin( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:flQueueTime ) { switch( iFailState ) { case TQUERY_CONNECT_FAILED: { log_amx( "Error connecting to SQL: %s", szError ); } case TQUERY_QUERY_FAILED: { log_amx( "Error checking login: %s", szError ); } case TQUERY_SUCCESS: { new iPlayer = iData[ 0 ]; if( SQL_ReadResult( hQuery, 0 ) > 0 ) { client_print( iPlayer, print_chat, "* Successfully logged in!" ); } else { client_print( iPlayer, print_chat, "* Login failed!" ); } } } }
What's the difference between Threaded and Unthreaded?
And which is better to use in plugin that, sends, gets and compares TIMES, SIDS, NAMES, MAPNAMES from SQL?
FiFiX is offline
Send a message via Skype™ to FiFiX
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-08-2010 , 16:36   Re: MqSql
Reply With Quote #15

Threaded queries are better because they are executed when the server can execute them instead of forcing the server to execute them at that very moment.
Threaded queries should be used but unthreaded queries are fine if your server isn't having any problems with them.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
FiFiX
Senior Member
Join Date: May 2008
Location: Poland
Old 10-08-2010 , 17:33   Re: MqSql
Reply With Quote #16

Thank You, Exolent ;]

Last edited by Exolent[jNr]; 10-08-2010 at 17:40. Reason: Don't hijack someone's thread.
FiFiX is offline
Send a message via Skype™ to FiFiX
Old 10-08-2010, 20:34
shuttle_wave
This message has been deleted by shuttle_wave.
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:16.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode