Raised This Month: $ Target: $400
 0% 

Need mysql base


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
reinert
Veteran Member
Join Date: Feb 2007
Old 06-08-2010 , 04:53   Need mysql base
Reply With Quote #1

Hey, can someone give me a Base example for plugin with SQLx, that when player joins server server checks if there is a row in mysql with his name, and if there isn't that name server send a message to mysql like create table with players name which connected to server. i hope you understood what I tried to tell you ;/
reinert is offline
unnyquee
Senior Member
Join Date: Jun 2009
Location: Constanta, Romania
Old 06-08-2010 , 05:13   Re: Need mysql base
Reply With Quote #2

There's a tut by Hawk, in Scripting section.
__________________
unnyquee is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 06-08-2010 , 05:53   Re: Need mysql base
Reply With Quote #3

PHP Code:
public client_connect(id)
{   


How can I Check is user already in table ?

PHP Code:
new szName[33]
get_user_name(idszName32)
new 
Handle:Query SQL_PrepareQuery(SqlConnection,"SELECT * FROM users WHERE name='%s'"szName
Now how can I check if there is no matches found in table with that name ?
reinert is offline
unnyquee
Senior Member
Join Date: Jun 2009
Location: Constanta, Romania
Old 06-08-2010 , 06:28   Re: Need mysql base
Reply With Quote #4

PHP Code:
if(SQL_Execute(Query))
{
      if(!
SQL_NumRows(Query))
            
// there's no matches

      
else
            
// match found.

__________________
unnyquee is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 06-08-2010 , 06:34   Re: Need mysql base
Reply With Quote #5

Ah, so how can I create a new row,


PHP Code:
SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS zomg (you INT(11),are INT(11),a INT(11),noob INT(11))"
This creates a Table, but how can I add a row with szName in it.

EDIT: now i'm having error in my logs:

Quote:
L 06/08/2010 - 14:53:23: [AMXX] Displaying debug trace (plugin "sql.amxx")
L 06/08/2010 - 14:53:23: [AMXX] Run time error 1: forced exit
L 06/08/2010 - 14:53:23: [AMXX] [0] sql.sma::plugin_init (line 47)
Line 47:

Quote:
if(!SQL_Execute(Queries[Count]))
{
// if there were any problems
SQL_QueryError(Queries[Count],g_Error,511)
set_fail_state(g_Error)
}

Last edited by reinert; 06-08-2010 at 06:55.
reinert is offline
unnyquee
Senior Member
Join Date: Jun 2009
Location: Constanta, Romania
Old 06-08-2010 , 07:50   Re: Need mysql base
Reply With Quote #6

That's because it can't connect to database, I suppose. Not sure, though.

Write this right before you're getting amx_sql_* variables for DB connection.

PHP Code:
server_cmd("sql.cfg");
server_exec(); 
__________________
unnyquee is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 06-08-2010 , 07:53   Re: Need mysql base
Reply With Quote #7

I Edited my connection line

PHP Code:
#define Host "localhost"
#define User "root"
#define Pass "mypass"
#define Db "users" 
PHP Code:
    g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db
Is there a problem ?
reinert is offline
unnyquee
Senior Member
Join Date: Jun 2009
Location: Constanta, Romania
Old 06-08-2010 , 07:55   Re: Need mysql base
Reply With Quote #8

You've cutted from the first part of the debug message..
__________________
unnyquee is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 06-08-2010 , 10:00   Re: Need mysql base
Reply With Quote #9

b.t.w. my sql.cfg is already in use by other plugin.
reinert is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 06-08-2010 , 10:10   Re: Need mysql base
Reply With Quote #10

Moved to Scripting Help
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Reply


Thread Tools
Display Modes

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 05:16.


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