Raised This Month: $51 Target: $400
 12% 

Invalid query Handle 0 (error: 4)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zylius
SourceMod Donor
Join Date: Nov 2009
Old 05-13-2010 , 14:30   Invalid query Handle 0 (error: 4)
Reply With Quote #1

Hi, don't judge me too mutch, i'm new to sourcepawn and i got a problem.
There is a player managment script that i'm creating, it involves SQL database, yet i'm getting an error and after a lot of research and no luck i come here.
The error i'm getting is:
Native "SQL_FetchRow" reported: Invalid query Handle 0 (error: 4)
My Code:
PHP Code:
public Show_Vip_SMS(client)
{
    
//db_connection_settings
                
new Handle:kv CreateKeyValues("sql");
                
KvSetString(kv"driver""default");
                
KvSetString(kv"host""localhost");
                
KvSetString(kv"port""3306");
                   
KvSetString(kv"database""cache");
                
KvSetString(kv"user""Zylius2");
                
KvSetString(kv"pass""xxxx");


decl String:error[255];
new 
Handle:hDatabase SQL_ConnectCustom(kverrorsizeof(error), true);
CloseHandle(kv);
//db_connection_settings_end
//insert_new_user
if (hDatabase == INVALID_HANDLE)
{
    
LogError("SQL Connection Failed: %s"error);
    return;

    
decl String:query[255];
    
decl String:gIp[64];
    
decl String:gName[64];
    
GetClientIP(client,gIp,sizeof(gIp));
    
GetClientNameclientgNameMAX_NAME_LENGTH );
    
Format(querysizeof(query), "INSERT INTO `cache`.`147` (`IP`, `Nick`) VALUES ('%s', '%s');"gIpgName);
    new 
Handle:hQuery SQL_Query(hDatabasequery);
    
CloseHandle(hQuery);
    
//insert_new_user_end
    //get_his_nick_from_db
    
new String:Nick[65];
    
decl String:query2[255];
    
Format(query2sizeof(query2), "SELECT FROM `cache`.`147` WHERE IP = '%s'"gIp);
    new 
Handle:hQuery2 SQL_Query(hDatabasequery2);
    while (
SQL_FetchRow(hQuery2))
    {
        
SQL_FetchString(hQuery21Nicksizeof(Nick))
        
PrintToChat(client"Your nick %s"Nick);
    }
    
CloseHandle(hQuery2);
    
//get_his_nick_from_db_end
    

The Player's info is inserted intho the DB perfectly, thoe i cannot get his Nick name back :/.
Zylius is offline
Scone
Senior Member
Join Date: Apr 2010
Location: England
Old 05-13-2010 , 15:48   Re: Invalid query Handle 0 (error: 4)
Reply With Quote #2

Your query is wrong: "SELECT FROM..." should be "SELECT <field> FROM..."

If the query handle is invalid, you can use SQL_GetError to get the actual error message from MySQL, and then log it.
__________________
Scone is offline
Zylius
SourceMod Donor
Join Date: Nov 2009
Old 05-14-2010 , 09:20   Re: Invalid query Handle 0 (error: 4)
Reply With Quote #3

Quote:
Originally Posted by Scone View Post
Your query is wrong: "SELECT FROM..." should be "SELECT <field> FROM..."

If the query handle is invalid, you can use SQL_GetError to get the actual error message from MySQL, and then log it.
You were right, thanks.
Zylius 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 06:42.


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