Jump to content

[C++] Read from Database


Recommended Posts

Hello Guys,

I want read a Vnum from Database... 

However it does not work.

My Source code :

Spoiler

long CItem::GetPetVnum()
{
    char Query[1024 + 1];
    snprintf(Query, sizeof(Query), "SELECT Petvnum FROM pet_summon WHERE PetSummonItemVnum='%d'", GetVnum());
    std::auto_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(Query));
    MYSQL_ROW row = mysql_fetch_row(msg->Get()->pSQLResult);
    long alrow = atoi(row[0]);
    sys_log(0, "TEST_VNUM : %d\n", alrow);
    return alrow;
}

5673950941c14cf08b271f5546eb5aa3.png

What is wrong?

Thanks for your help!

Sorry for my bad English .. :D

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

	 long CItem::GetPetVnum()
{
    char szQuery[1024];
    snprintf(szQuery, sizeof(szQuery), "SELECT Petvnum FROM pet_summon WHERE PetSummonItemVnum='%d'", GetVnum());
    std::auto_ptr<SQLMsg> msg(CDBManager::instance().DirectQuery(szQuery));
  MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
    long alrow = atoi(row[0]);
    sys_log(0, "TEST_VNUM : %d\n", alrow);
    return alrow;
}

try this

  • Love 1
Link to comment
Share on other sites

  • Active Member
9 minutes ago, Fazer said:

try this



	 long CItem::GetPetVnum()
{
    char szQuery[1024 + 1];
    snprintf(szQuery, sizeof(szQuery), "SELECT Petvnum FROM pet_summon WHERE PetSummonItemVnum='%d'", GetVnum());
    std::auto_ptr<SQLMsg> msg(CDBManager::instance().DirectQuery(szQuery));
  MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
    long alrow = atoi(row[0]);
    sys_log(0, "TEST_VNUM : %d\n", alrow);
    return alrow;
}

change name?XDDD

 

#topic

try this ;)

long CItem::GetPetVnum()
{
    char szQuery[1024];
    snprintf(szQuery, sizeof(szQuery), "SELECT Petvnum FROM pet_summon WHERE PetSummonItemVnum = %u LIMIT 1", GetVnum());
    std::auto_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(szQuery));

    if (msg->Get()->uiNumRows > 0)
    {
        MYSQL_ROW row = mysql_fetch_row(msg->Get()->pSQLResult);
        long alrow = atoi(row[0]);
        sys_log(0, "TEST_VNUM : %l\n", alrow);
        return alrow;
    }
    else
        return -1;
}

 

 

 

 

 

 

 

  • Love 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.