MySQL: Fields/Rows are empty
#1

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
Reply
#2

UP, guys, I really need help...
Reply
#3

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

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.
Reply
#5

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!
Reply
#6

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
Reply
#7

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

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)