AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Need mysql base (https://forums.alliedmods.net/showthread.php?t=129027)

reinert 06-08-2010 04:53

Need mysql base
 
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 ;/

unnyquee 06-08-2010 05:13

Re: Need mysql base
 
There's a tut by Hawk, in Scripting section.

reinert 06-08-2010 05:53

Re: Need mysql base
 
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 ?

unnyquee 06-08-2010 06:28

Re: Need mysql base
 
PHP Code:

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

      
else
            
// match found.



reinert 06-08-2010 06:34

Re: Need mysql base
 
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)
}

unnyquee 06-08-2010 07:50

Re: Need mysql base
 
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(); 


reinert 06-08-2010 07:53

Re: Need mysql base
 
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 ?

unnyquee 06-08-2010 07:55

Re: Need mysql base
 
You've cutted from the first part of the debug message..

reinert 06-08-2010 10:00

Re: Need mysql base
 
b.t.w. my sql.cfg is already in use by other plugin.

YamiKaitou 06-08-2010 10:10

Re: Need mysql base
 
Moved to Scripting Help


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

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