24.06.2012, 08:52
Use this function to select the amount of rows in a database.
Selecting a wildcard is a waste of memory when you can use COUNT(*).
Here is an example of how to use that stock.
pawn Код:
stock db_get_rows(DB:database, tablename[])
{
new
query[50],
DBResult:result,
field[128]
;
format(query, sizeof(query), "SELECT COUNT(*) FROM `%s`", tablename);
result = db_query(database, query);
db_get_field_assoc(result, "COUNT(*)", field, sizeof(field));
db_free_result(result);
return strval(field);
}
Here is an example of how to use that stock.
pawn Код:
new
rows = db_get_rows(ExampleDB, "ExampleTableName");
printf("This table has %d rows.", rows);