SA-MP Forums Archive
MySQL: Fields/Rows are empty - 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: Fields/Rows are empty (/showthread.php?tid=341888)



MySQL: Fields/Rows are empty - zgintasz - 12.05.2012

Hi guys,

MySQL doesn't load a gang name. I'm getting empty string(""):
pawn Код:
printf( "Name: %s", GetGangName( 1 ) ); // Result: "Name: "
pawn Код:
stock GetGangName( gaujosID )
{
    new
        gPavadinimas[ 22 ]
    ;
    format( query, sizeof( query ), "SELECT `gPavadinimas` FROM `gaujos` WHERE `gID` = %d", gaujosID );
    mysql_query( query );
    mysql_store_result( );
    mysql_get_field( "gPavadinimas", gPavadinimas );
    mysql_free_result( );
    return gPavadinimas;
}
Here is mysql log:
Код:
8:39:37] CMySQLHandler::Query(SELECT gPavadinimas FROM gaujos WHERE gID = 1) - Successfully executed.
 
[18:39:37] >> mysql_store_result( Connection handle: 1 )
 
[18:39:37] CMySQLHandler::StoreResult() - Result was stored.
 
[18:39:37] >> mysql_fetch_field_row( Connection handle: 1 )
 
[18:39:37] CMySQLHandler::FetchField(gPavadinimas) - You cannot call this function now. (Reason: Fields/Rows are empty.)
 
[18:39:37] >> mysql_free_result( Connection handle: 1 )
 
[18:39:37] CMySQLHandler::FreeResult() - Result was successfully free'd.
It says Fields/Rows are empty, but they aren't empty!

How to fix this?


Sorry for my bad English...
Thanks


Re: MySQL: Fields/Rows are empty - zgintasz - 12.05.2012

UP, guys, I really need help...


Re: MySQL: Fields/Rows are empty - Pinguinn - 12.05.2012

Try changing
pawn Код:
WHERE `gID` = %d
to
pawn Код:
WHERE `gID` = '%d'



Re: MySQL: Fields/Rows are empty - AndreT - 12.05.2012

Integers do not need to be enclosed in quotes. In fact, a query
SELECT gPavadinimas FROM gaujos WHERE gID = %d
is perfectly valid as well. You don't need to use single quotes unless you have a string or a word that will be handled specially (as a keyword) by MySQL.

zgintasz, run the same query in phpMyAdmin and see if it gives a valid result. Assuming it does, try using a different function for handling the loading of this string. As far as I know, you're selecting only one field, but then using a very comprehensive function to access it! There must be something simpler like mysql_fetch_row.


Re: MySQL: Fields/Rows are empty - zgintasz - 12.05.2012

Thanks for reply. Query in phpMyAdmin returns a correct value. I changed
pawn Код:
mysql_get_field( "gPavadinimas", gPavadinimas );
to
pawn Код:
mysql_fetch_row_format( query, "|" );
format( gPavadinimas, sizeof( gPavadinimas ), "%s", query );
and it works correctly. Thanks!


Re: MySQL: Fields/Rows are empty - Pinguinn - 12.05.2012

Quote:
Originally Posted by AndreT
Посмотреть сообщение
Integers do not need to be enclosed in quotes. In fact, a query
SELECT gPavadinimas FROM gaujos WHERE gID = %d
is perfectly valid as well. You don't need to use single quotes unless you have a string or a word that will be handled specially (as a keyword) by MySQL.

zgintasz, run the same query in phpMyAdmin and see if it gives a valid result. Assuming it does, try using a different function for handling the loading of this string. As far as I know, you're selecting only one field, but then using a very comprehensive function to access it! There must be something simpler like mysql_fetch_row.
Then I assume strings needed to be enclosed


Re: MySQL: Fields/Rows are empty - AndreT - 12.05.2012

zgintasz, I think your code can be improved even further:
pawn Код:
mysql_fetch_row_format(gPavadinimas, "|");



Re: MySQL: Fields/Rows are empty - Evoturk - 12.05.2012

Quote:
Originally Posted by zgintasz
Посмотреть сообщение
Thanks for reply. Query in phpMyAdmin returns a correct value. I changed
pawn Код:
mysql_get_field( "gPavadinimas", gPavadinimas );
to
pawn Код:
mysql_fetch_row_format( query, "|" );
format( gPavadinimas, sizeof( gPavadinimas ), "%s", query );
and it works correctly. Thanks!
Thanks , i had same problem. When I used it, problem solved.