Exemples:
Simple bank plugin:
PHP Code:
new db_money;
public OnPluginStart()
{
}
public DB_OnRowsUpdated(){
db_money = DB_GetColumnId("my_money", true, true, DB_INT);
if(db_money == -1)
SetFailState("[SMbank] Could not create money column!");
}
stock GetUserMoney(client){
return DB_GetColumn( client, db_money );
}
stock SetUserMoney(client, money){
return DB_SetInfo(client, db_money , money);
}
This function is called right after the server receives information from the database.
DO NOT try to use DB_GetColumn on player OnClientConnect or anything of the type.
PHP Code:
public DB_OnClientUpdate(client){
//Do something...
}
Note: Information is saved on OnClientDisconnect_Post, so it is OK to do this:
PHP Code:
public OnClientDisconnect(client){
DB_SetInfo( client, db_money, 5000 );
}
Functions
PHP Code:
#define DB_INT 0
#define DB_STRING 1
#define DB_FLOAT 2
/**
* Gets the ID of a row
* @param RowName Name of the mysql Column you want to get
* @param autoenable To enable this row on select query
* @param autocreate If the row does not exist, create it
* @param rowtype row type if it is being created
* @param rowsize row size if it is being created, 0 = default, float has no size
*/
native DB_GetColumnId(const String:RowName[], bool:autoenable = true, bool:autocreate = false, rowtype = DB_INT, rowsize = 0);
/**
* Gets the ID of a row
* @param Enable Row id from fetching when client connect
*/
native DB_EnableId( ColumnId );
/**
* Gets the ID of a row
* @param Disable Row Id from fetching when client connect
*/
native DB_DisableId( ColumnId );
/**
* Gets the ID of a row
* @param client Client ID for set info
* @param ColumnId The column ID for set info
* @param value The information to set it to
* @param add Set to true if you want to add the value to the old amount
*/
native DB_SetInfo( client, ColumnId, any:value , bool: add = false);
native DB_SetInfoString( client, ColumnId, const String:name[] );
/**
* Gets the ID of a row
* @param client Client ID for get info
* @param ColumnId The column ID for get info
*/
native any:DB_GetColumn( client , ColumnId );
native DB_GetColumnString( client, ColumnId, String:value[], maxsize);
/**
* Gets the ID of a row
* @param RowName Name of the mysql Column you want to get
*/
native DB_ColumnType( ColumnId );
/**
* Returns the DB handle, for your own personal use
*/
native Handle:DB_GetHandle( );
/**
* Gets the ID of a row
* @param RowName The name of the new row
* @param RowType Use DB_* and define the new row type
* @param Size The size of this now row, leave blank for default
* @return RowId, -1 on failure
*/
stock DB_CreateRow( const String:Rowname[], Rowtype= DB_INT, size = 0 ){
return DB_GetColumnId(RowName, true, true, Rowtype , size);
}
/**
* Called when info of a client has been updated
* @param client client
*/
forward DB_OnClientUpdate(client);
__________________