SA-MP Forums Archive
[MYSQL]Mysql_Get_field returns empty even though there is something there - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [MYSQL]Mysql_Get_field returns empty even though there is something there (/showthread.php?tid=449441)



[MYSQL]Mysql_Get_field returns empty even though there is something there - thimo - 08.07.2013

Okay so i have a weird problem. As i try to make my car loading system my server returns 0 rows back even when there is. Code:
pawn Код:
format(str, sizeof(str), "SELECT `HouseID` FROM `Houses` WHERE `Houseowner`='%s'", name);
    mysql_real_escape_string(str, string1);
    mysql_query(string1);
    mysql_store_result();
    mysql_get_field("HouseID", string1); //Gets the first field of the row returned (HouseID)
    mysql_free_result();
The mysql log outputs this:
Код:
[13:10:08] CMySQLHandler::Query(SELECT `HouseID` FROM `Houses` WHERE `Houseowner`='Thimo') - Successfully executed.

[13:10:08] >> mysql_store_result( Connection handle: 1 )

[13:10:08] CMySQLHandler::StoreResult() - Result was stored.

[13:10:08] >> mysql_fetch_field_row( Connection handle: 1 )

[13:10:08] CMySQLHandler::FetchField(HouseID) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[13:10:08] >> mysql_free_result( Connection handle: 1 )

[13:10:08] CMySQLHandler::FreeResult() - Result was successfully free'd.
Proof of that there is something in there:
Uploaded with ImageShack.us

Now what could be wrong?


Re: [MYSQL]Mysql_Get_field returns empty even though there is something there - GiamPy. - 08.07.2013

Your script uses an outdated and deprecated MySQL plugin.
I highly suggest you to upgrade your script to something more updated.

https://sampforum.blast.hk/showthread.php?tid=56564

As for the error, is that the only piece of code that is refered to the logs?


Re: [MYSQL]Mysql_Get_field returns empty even though there is something there - thimo - 08.07.2013

pawn Код:
format(str, sizeof(str), "SELECT `HouseID` FROM `Houses` WHERE `Houseowner`='%s'", name);
    mysql_real_escape_string(str, string1);
    mysql_query(string1);
    mysql_store_result();
    mysql_get_field("HouseID", string1); //Gets the first field of the row returned (HouseID)
    mysql_free_result();
    if(!sscanf(str, "d", integer))
    {
        if(integer != 0) //Player has a house...
        {
            format(string, sizeof(string), "SELECT * FROM `Vehicles` WHERE `HouseID`= '%d'", integer);
            mysql_query(string);
            if(mysql_num_rows() != 0)
            {
                while(mysql_num_rows()) //Loop xD
                {
                    //Do what you want with the vehicle :P
                    //Use db_get_field or db_get_field_assoc
                    //Remember to store the vehicle IDs in a variable so you can delete them in OnPlayerDisconnect
                    mysql_get_field("Model", cModel);
                    mysql_get_field("X", cx);
                    mysql_get_field("Y", cy);
                    mysql_get_field("Z", cz);
                    mysql_get_field("Rot", crot);
                    mysql_get_field("Color1", Col1);
                    mysql_get_field("Color2", Col2);
                    new hId = strval(str);
                    House_AddVehicle(hId, strval(cModel), floatstr(cx), floatstr(cy), floatstr(cz), floatstr(crot), strval(Col1), strval(Col2));
                    print("Car loaded");
                }
                print("Does work");
            }

        }
    }
This is the whole code.


Re: [MYSQL]Mysql_Get_field returns empty even though there is something there - ReVo_ - 08.07.2013

Wait a bit man, the query fails while checks for Houses not vehicle.
Why you post the screen of the vehicles?

Check if exists any house owner with that name.


Re: [MYSQL]Mysql_Get_field returns empty even though there is something there - thimo - 08.07.2013

Here a pic that there is an Houseowner called Thimo
Uploaded with ImageShack.us