Hello! I want to get a string from my database and i use this code:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>
new Handle:g_SqlTuple
new g_Error[512]
new g_pcvarHost
new g_pcvaruUser
new g_pcvarPass
new g_pcvarDB
public plugin_init()
{
register_plugin("SQLx Demonstration","1.0","Hawk552")
g_pcvarHost = register_cvar( "redirect_sql_host", "csbots.ro" )
g_pcvaruUser = register_cvar( "redirect_sql_user", "csbotsro_sql" )
g_pcvarPass = register_cvar( "redirect_sql_pass", "%DzC4qB-r%Qm" )
g_pcvarDB = register_cvar( "redirect_sql_db", "csbotsro_sql" )
new szHost[ 32 ]
new szUser[ 32 ]
new szPass[ 32 ]
new szDB[ 32 ]
get_pcvar_string( g_pcvarHost, szHost, charsmax( szHost ) )
get_pcvar_string( g_pcvaruUser, szUser, charsmax( szUser ) )
get_pcvar_string( g_pcvarPass, szPass, charsmax( szPass ) )
get_pcvar_string( g_pcvarDB, szDB, charsmax( szDB ) )
// we tell the API that this is the information we want to connect to,
// just not yet. basically it's like storing it in global variables
g_SqlTuple = SQL_MakeDbTuple( szHost, szUser, szPass, szDB )
// ok, we're ready to connect
new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
if(SqlConnection == Empty_Handle)
// stop the plugin with an error message
set_fail_state(g_Error)
new Handle:Queries
// we must now prepare some random queries
Queries = SQL_PrepareQuery(SqlConnection,
"CREATE TABLE IF NOT EXISTS servers (id INT(11),adress VARCHAR(60),hostname VARCHAR(100),players INT(11),maxplayers INT(11),map VARCHAR(100),status INT(11),game VARCHAR(50),date_create INT(11),date_end INT(11),type INT(11),rounds TEXT)")
//Queries[1] = SQL_PrepareQuery(SqlConnection,
//"INSERT INTO `servers`(`id`, `address`, `hostname`, `players`, `maxplayers`, `map`, `status`, `game`, `date_create`, `date_end`, `type`, `rounds`) VALUES ('0','127.0.0.1','test','20','32','de_dust2','online','cstrike','01.01.2015','01.02.2015','3','0')")
if(!SQL_Execute(Queries))
{
// if there were any problems
SQL_QueryError(Queries,g_Error,511)
set_fail_state(g_Error)
}
// close the handle
SQL_FreeHandle(Queries)
// you free everything with SQL_FreeHandle
SQL_FreeHandle(SqlConnection)
set_task ( 15.0, "GetSQLData" );
}
public GetSQLData()
{
// ok, we're ready to connect
new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
if(SqlConnection == Empty_Handle)
// stop the plugin with an error message
set_fail_state(g_Error)
// run a random query
new Handle:Query = SQL_PrepareQuery(SqlConnection,"SELECT `address` FROM `servers`")
// run the query
if(!SQL_Execute(Query))
{
// if there were any problems
SQL_QueryError(Query,g_Error,511)
set_fail_state(g_Error)
}
// checks to make sure there's more results
// notice that it starts at the first row, rather than null
new Data
while(SQL_MoreResults(Query))
{
// columns start at 0
Data = SQL_ReadResult(Query,0)
server_print("Found data: %d",Data)
SQL_NextRow(Query)
}
// of course, free the handle
SQL_FreeHandle(Query)
// and of course, free the connection
SQL_FreeHandle(SqlConnection)
}
public plugin_end()
// free the tuple - note that this does not close the connection,
// since it wasn't connected in the first place
SQL_FreeHandle(g_SqlTuple)
Good, if i use "%d" in that part:
PHP Code:
new Data
while(SQL_MoreResults(Query))
{
// columns start at 0
Data = SQL_ReadResult(Query,0)
server_print("Found data: %d",Data)
SQL_NextRow(Query)
}
The server will print: Found data: 127
But in my database is: 127.0.0.1
So, that is a String, not a number.
My question is, how can i get the full string ?
Thank you!