AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   DBI codeing problem (https://forums.alliedmods.net/showthread.php?t=26822)

lucky109 04-09-2006 17:16

DBI codeing problem
 
1 Attachment(s)
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~

slurpycof 04-09-2006 20:26

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

lucky109 04-10-2006 04:10

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><

Xanimos 04-10-2006 07:41

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) }

lucky109 04-10-2006 08:14

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><

nhdriver4 04-10-2006 09:56

The code that Suicid3 provided was only an example. It will not function as it is. Modify it to suit your needs.

lucky109 04-12-2006 07:19

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><

Xanimos 04-12-2006 07:47

Do you have a mysql table named "table" with one row called "value" ?

lucky109 04-13-2006 04:16

2 Attachment(s)
Quote:

Originally Posted by Suicid3
Do you have a mysql table named "table" with one row called "value" ?

i have~see the picture

lucky109 04-14-2006 03:33

help/.\


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

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