To retrieve a string from a MySQL database without mysql_fetch_row_format?
#9

pawn Код:
//some query
mysql_store_result();
if(mysql_retrieve_row()) //there are actually any rows
{
   mysql_get_field("fieldname",wheretostorevalue); //macro for mysql_fetch_field_row
   mysql_get_field(...);
   mysql_get_field(...);
   mysql_get_field(...);
   mysql_get_field(...);
}
else //there aren't
{

}
mysql_free_result();
Upper example is when you operate only with one row (for example player login). If you expect many rows (for examples when you select something from vehicles table) you use while.

pawn Код:
//some query
mysql_store_result();
while(mysql_retrieve_row()) //it will be running until there are no more rows to be retrieved
{
   mysql_get_field("fieldname",wheretostorevalue); //macro for mysql_fetch_field_row
   mysql_get_field(...);
   mysql_get_field(...);
   mysql_get_field(...);
   mysql_get_field(...);
}
mysql_free_result();
Using this method rather than mysql_fetch_row_format + sscanf combination is better because if you add another field in the table you will need to modify that long sscanf line and it's easy to mix things up. With this method you just add another line to get new field's value and that's it. Also it's easier if you don't use all fields which you get because you just don't get them, while in sscanf you would need to use quiet function on them
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)