Raised This Month: $ Target: $400
 0% 

DBI codeing problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lucky109
Senior Member
Join Date: Jan 2005
Old 04-09-2006 , 17:16   DBI codeing problem
Reply With Quote #1

Quote:
new const PLUGINNAME[] = "test"
new const VERSION[] = "test"
new const AUTHOR[] = "test"

#include <amxmodx>
#include <dbi>

new Sql:dbc
new Result:result

public plugin_init() {
register_plugin(PLUGINNAME, VERSION, AUTHOR)
set_task(Float:10.0,"sql_init")
}

public sql_init() {
new host[64], username[32], password[32], dbname[32], error[32]

get_cvar_string("amx_sql_host",host,64)
get_cvar_string("amx_sql_user",username,32)
get_cvar_string("amx_sql_pass",password,32)
get_cvar_string("amx_sql_db",dbname,32)

dbc = dbi_connect(host,username,password,dbname,err or,32)

if (dbc == SQL_FAILED)
log_amx("SQL Connection Failed")
else
dbi_query(dbc,"CREATE TABLE IF NOT EXISTS `test` (`value` varchar(20) NOT NULL)")
}

public client_putinserver(id) {
result = dbi_query(dbc,"SELECT value FROM test")
dbi_free_result(result)
new userinfo[64]
new name[32]
get_user_name(id,name,31)
get_user_info(id,"ABC",userinfo,63)
if(equal(userinfo,"%s"))
{
}
else {
server_cmd("kick #%d ^"%L^"",get_user_userid(id),LANG_SERVER,"kick _reson")
}
}

what's wrong?
kicked by server if i'm using setinfo "ABC" "1"

help me please thanks~
Attached Images
File Type: png aaaa.png (2.3 KB, 264 views)
lucky109 is offline
slurpycof
Senior Member
Join Date: Nov 2004
Old 04-09-2006 , 20:26  
Reply With Quote #2

ummmm, where is the rest of your code?

and an fyi

set_task(Float:10.0,"sql_init")

means at map change anyone that has the map and a semi decent computer will cause you to get a invalid db handle error.

set_task(Float:0.1,"sql_init") may even give you the error sometimes if user system is high end
slurpycof is offline
lucky109
Senior Member
Join Date: Jan 2005
Old 04-10-2006 , 04:10  
Reply With Quote #3

oh,thanks~
updated~

but it's can't run too~

Quote:
$query = mysql_query("SELECT value FROM table");
while($row=mysql_fetch_array($query)) {
$test .= $row[value];
}

Quote:
result = dbi_query(dbc,"SELECT value FROM test")
dbi_free_result(result)
this's php code=-="
how to change to AMXX code><
lucky109 is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 04-10-2006 , 07:41  
Reply With Quote #4

Code:
result = dbi_query(dbc,"SELECT value FROM table"); if(result <= RESULT_FAILED) {     new szError[76];     dbi_error(dbc , szError , 75);     server_print("[MyPlug] Error in SQL : %s" , szError); } else {     new szAppend[126] , iLen;     new szValue[36];  // or new iValue; or new Float:fValue;     while(dbi_nextrow(result))     {         //Note: this isn't appending to the string. It is replacing it everytime.         dbi_result(result , "value" , szValue , 35);         //or iValue = dbi_result( result , "value");         //or dbi_result( result , "value" , fValue);         //This is how you can append a value to a string.         iLen += format(szAppend[iLen] , 125 - iLen , "%s" , szValue);         //or iLen += format(szAppend[iLen] , 125 - iLen , "%d" , iValue);         //or iLen += format(szAppend[iLen] , 125 - iLen , "%f" , fValue);     }     dbi_free_result(result) }
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
lucky109
Senior Member
Join Date: Jan 2005
Old 04-10-2006 , 08:14  
Reply With Quote #5

Quote:
public client_putinserver(id) {

new userinfo[64]
new ipb[64]
new name[32]
get_user_name(id,name,31)
get_user_info(id,"ABC",userinfo,63)
get_user_ip(id,ipb,63)

result = dbi_query(dbc,"SELECT value FROM table");
if(result <= RESULT_FAILED)
{
new szError[76];
dbi_error(dbc , szError , 75);
server_print("[MyPlug] Error in SQL : %s" , szError);
}
else
{
new szAppend[126] , iLen;
new szValue[36];
while(dbi_nextrow(result))
{
dbi_result(result , "value" , szValue , 35);
iLen += format(szAppend[iLen] , 125 - iLen , "%s" , szValue);
}
if(equal(userinfo,"%s"))
{
}
else {
server_cmd("kick #%d ^"%L^"",get_user_userid(id),LANG_SERVER,"kick _reason")
}
dbi_free_result(result)
}
}
Error in SQL : You have an errorin your SQL syntax; check the manual that corresoonds to

i'm a noob/.\" help><
lucky109 is offline
nhdriver4
Senior Member
Join Date: Nov 2005
Old 04-10-2006 , 09:56  
Reply With Quote #6

The code that Suicid3 provided was only an example. It will not function as it is. Modify it to suit your needs.
__________________
nhdriver4 is offline
Send a message via AIM to nhdriver4
lucky109
Senior Member
Join Date: Jan 2005
Old 04-12-2006 , 07:19  
Reply With Quote #7

Quote:
public client_putinserver(id) {

new userinfo[64]
new ipb[64]
new name[32]
get_user_name(id,name,31)
get_user_info(id,"ABC",userinfo,63)
get_user_ip(id,ipb,63)

result = dbi_query(dbc,"SELECT value FROM table");
if(result <= RESULT_FAILED)
{
new szError[76];
dbi_error(dbc , szError , 75);
server_print("[MyPlug] Error in SQL : %s" , szError);
}
else
{
new szAppend[126] , iLen;
new szValue[36];
while(dbi_nextrow(result))
{
dbi_result(result , "value" , szValue , 35);
iLen += format(szAppend[iLen] , 125 - iLen , "%s" , szValue);
}
if(equal(userinfo,"%s"))
{
}
else {
server_cmd("kick #%d ^"%L^"",get_user_userid(id),LANG_SERVER,"kick _reason")
}
dbi_free_result(result)
}
}
Error in SQL : You have an errorin your SQL syntax; check the manual that corresoonds to

i'm a noob><
why why why tell me why><
lucky109 is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 04-12-2006 , 07:47  
Reply With Quote #8

Do you have a mysql table named "table" with one row called "value" ?
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
lucky109
Senior Member
Join Date: Jan 2005
Old 04-13-2006 , 04:16  
Reply With Quote #9

Quote:
Originally Posted by Suicid3
Do you have a mysql table named "table" with one row called "value" ?
i have~see the picture
Attached Images
File Type: png aaaa.png (2.3 KB, 226 views)
File Type: jpg bbb.jpg (17.7 KB, 201 views)
lucky109 is offline
lucky109
Senior Member
Join Date: Jan 2005
Old 04-14-2006 , 03:33  
Reply With Quote #10

help/.\
lucky109 is offline
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 16:40.


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