[HELP] MySQL Load
#1

Hello,
I'm making a Car system, this is my first MySQL Dynamic System, i need help. How can i make a Load.
In OnGameModeInit i have this:
UcitajAuta();
I maked a enums,MAX_CARS and that...
In UcitajAuta I have somthing like this but dont work, my version of MySQL is R31.
Код:
stock UcitajAuta()
{
    for(new i; i < MAX_CARS; i++)
    {
		new query[256];
		format(query, sizeof(query),"SELECT * FROM cars WHERE id=%d",i);
		mysql_tquery(query);
		mysql_store_result();
    }
}
Reply
#2

If your version of MySQL is R31, then use threaded queries.
pawn Код:
stock UcitajAuta( )
{
    mysql_function_query( YOUR_CONNECTION_HERE, "SELECT * FROM `cars`", true, "OnCarsLoad", "" ); // CHANGE ME!
}

forward OnCarsLoad( );
public OnCarsLoad( )
{
    new
        rows,
        fields
    ;
    cache_get_data( rows, fields, YOUR_CONNECTION_HERE ); // CHANGE ME!

    if( rows )
    {
        new
            i = 0
        ;
        while( rows > i < MAX_CARS )
        {
            // Load them using cache_get_row (sting), cache_get_row_int (integer), cache_get_row_float (float)
            i++;
        }
    }
}
Reply
#3

Konstantinos thanks, i have small problem.
cache_get_data( rows, fields, YOUR_CONNECTION_HERE ); // CHANGE ME!
What i must type in "YOUR_CONNECTION_HERE"
For mysql_function_query i make like this
new ConnectToDatabase = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_BASE, MYSQL_PASS);
mysql_function_query( ConnectToDatabase, "SELECT * FROM `cars`", true, "OnCarsLoad", "" ); // CHANGE ME!
Reply
#4

I solve somthing, is this good?
dbHandle is mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_BASE, MYSQL_PASS);
stock UcitajAuta( )
{
mysql_function_query( dbHandle, "SELECT * FROM `cars`", true, "OnCarsLoad", "" );
}

forward OnCarsLoad( );
public OnCarsLoad( )
{
new
rows,
fields;

cache_get_data( rows, fields, dbHandle ); // CHANGE ME!

if( rows )
{
new
i = 0
;
while( rows > i < MAX_CARS )
{
CarInfo[i][kID] = cache_get_field_content_int(0, "kID");
i++;
}
}
}
Reply
#5

The variable's name you're using to mysql_connect.

If it's:
pawn Код:
new ConnectToDatabase = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_BASE, MYSQL_PASS);
then:
pawn Код:
mysql_function_query( ConnectToDatabase, "SELECT * FROM `cars`", true, "OnCarsLoad", "" );
Reply
#6

I make this:

Код:
stock LoadCars( )
{
    mysql_function_query( dbHandle, "SELECT * FROM `cars`", true, "OnCarsLoad", "" );
}

forward OnCarsLoad( );
public OnCarsLoad( )
{
    new
        rows,
        fields;

    cache_get_data( rows, fields, dbHandle ); // CONNECTION

    if( rows )
    {
        new
            i = 0
        ;
        while( rows > i < MAX_CARS )
        {
            CarInfo[i][kID] = cache_get_field_content_int(0, "kID");
            cache_get_field_content(0, "kVlasnik", CarInfo[i][kVlasnik], dbHandle, 50);
            CarInfo[i][kUlazX] = cache_get_field_content_float(0, "kUlazX");
            CarInfo[i][kUlazY] = cache_get_field_content_float(0, "kUlazY");
            CarInfo[i][kUlazZ] = cache_get_field_content_float(0, "kUlazZ");
            i++;
        }
    }
}
But in MySQL log there is this:
Код:
[14:28:04] [ERROR] "mysql_tquery" - invalid connection handle. (ID = 0).
Reply
#7

It seems like it uses another connection handle id.

Do you connect to the mysql by doing:
pawn Код:
dbHandle = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_BASE, MYSQL_PASS);
Reply
#8

On the top: new dbHandle
On the OnGameModeInit
dbHandle = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_BASE, MYSQL_PASS);
Reply
#9

I don't know why, it's better to post it to MySQL's thread. I'm sure someone who knows will help you on that.
Reply
#10

BUMP!
I make like this but dont work.
mysql_tquery( dbHandle, "SELECT * FROM `cars`", "OnCarsLoad", "" );
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)