Raised This Month: $ Target: $400
 0% 

sql-problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-05-2007 , 13:16   Re: sql-problem
Reply With Quote #1

Quote:
Originally Posted by YamiKaitou View Post
PHP Code:
new nick[64];
SQL_ReadResult(Query,SQL_FieldToNum(Query,"nick"),nick,63); 
IT doesnt work. I just keep getting int-values from the db, when the values in the db are STR. What im looking for is this.

PHP Code:
$array mysql_query("SELECT * FROM login");
while(
$row mysql_fetch_array($array)) 
{
  echo  
$row[nick];

This is how it would have looked in php.
lagbeast is offline
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-05-2007 , 15:48   Re: sql-problem
Reply With Quote #2

Quote:
Originally Posted by YamiKaitou View Post
PHP Code:
new nick[64];
SQL_ReadResult(Query,SQL_FieldToNum(Query,"nick"),nick,63); 
Yeah i saw the typo and tried it, cuz i figured but i still get the same error. The field nick contains nicks and is a varchar 255, so it does contain strings but i still get INT-values. Im getting pissed.... and sad.
lagbeast is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-05-2007 , 14:25   Re: sql-problem
Reply With Quote #3

Typo, sorry

PHP Code:
new nick[64];
SQL_ReadResult(Query,SQL_FieldNameToNum(Query,"nick"),nick,63); 

Now, replace the "nick" part with the exact name of the colum you are trying to read from. Make sure it is still in quotes. This should work, the only reason why it wouldn't return a string is if the column doesn't contain a string.
__________________
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
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-05-2007 , 16:04   Re: sql-problem
Reply With Quote #4

Did you try the one I just posted? Cause you quoted my other post. I know this works cause I use it in my plugins using SQLite
__________________
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
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-05-2007 , 19:02   Re: sql-problem
Reply With Quote #5

Quote:
Originally Posted by YamiKaitou View Post
Did you try the one I just posted? Cause you quoted my other post. I know this works cause I use it in my plugins using SQLite
Yeah i just quoted the wrong one. Can you post your entire code and ill try that?
lagbeast is offline
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 07-05-2007 , 19:17   Re: sql-problem
Reply With Quote #6

Here's a snippet from my old RP mod over how i select and read tables.
Code:
new Handle:g_SqlTuple new g_Cache[512] public plugin_init() {     register_plugin(Plugin, Version, Author)     set_task(0.3, "sql_init") } public sql_init() {         new Host[64], User[64], Pass[64], Db[64]         get_cvar_string("amx_sql_host", Host, 63)         get_cvar_string("amx_sql_user", User, 63)         get_cvar_string("amx_sql_pass", Pass, 63)         get_cvar_string("amx_sql_db", Db, 63)         g_SqlTuple = SQL_MakeDbTuple(Host, User, Pass, Db)         SQL_ThreadQuery(g_SqlTuple, "SelectHandle3", "SELECT * FROM RP_Props") } public SelectHandle3(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {     if(FailState == TQUERY_CONNECT_FAILED)         return set_fail_state("Could not connect to SQL database.")     else if(FailState == TQUERY_QUERY_FAILED)         return set_fail_state("Query failed.")         if(Errcode)         return log_amx("Error on query: %s",Error)     while(SQL_MoreResults(Query))     {         SQL_ReadResult(Query, 0, prop_name[num_of_props], 63)       prop[num_of_props][0] = SQL_ReadResult(Query, 1)         prop[num_of_props][1] = SQL_ReadResult(Query, 2)     SQL_ReadResult(Query, 3, prop_owner_name[num_of_props], 31)     SQL_ReadResult(Query, 4, prop_owner[num_of_props], 31)         server_print("[DEBUG] Loaded prop %s - Owner %s", prop_name[num_of_props], prop_owner_name[num_of_props])             num_of_props++     SQL_NextRow(Query)     }         return PLUGIN_CONTINUE }

I hope that helps.
Deviance is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-05-2007 , 19:15   Re: sql-problem
Reply With Quote #7

I don't want to post my code, it is a private plugin specially designed for my server. But, I can post a snipit from it. I know that this works because the plugin works like it is suppose to.

PHP Code:
[ . . . ]
    
format(szquery,255,"SELECT * FROM `members` WHERE `steamid` = '%s'",authid);
    new 
Handle:query SQL_PrepareQuery(g_DBConn,szquery);
    if (!
SQL_Execute(query))
    {
        
SQLITE_Errorqueryszquery);
        
log("Error querying `members` 9");
        return;
    }
    if (
SQL_NumRows(query) != 0)
    {
        new 
name[64],rank[21];
        new 
colname SQL_FieldNameToNum(query,"name")
        new 
colrank SQL_FieldNameToNum(query,"rank")
        
SQL_ReadResult(query,colname,name,63);
        
SQL_ReadResult(query,colrank,rank,20);
        
        [ . . . ]
    }

    [ . . . ]
}

[ . . . ] 
__________________
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



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 21:26.


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