SA-MP Forums Archive
[HELP] MySQL Load - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP] MySQL Load (/showthread.php?tid=461765)



[HELP] MySQL Load - shulk - 03.09.2013

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();
    }
}



Re: [HELP] MySQL Load - Konstantinos - 03.09.2013

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++;
        }
    }
}



Re: [HELP] MySQL Load - shulk - 03.09.2013

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!


Re: [HELP] MySQL Load - shulk - 03.09.2013

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++;
}
}
}


Re: [HELP] MySQL Load - Konstantinos - 03.09.2013

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", "" );



Re: [HELP] MySQL Load - shulk - 03.09.2013

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).



Re: [HELP] MySQL Load - Konstantinos - 03.09.2013

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);



Re: [HELP] MySQL Load - shulk - 03.09.2013

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


Re: [HELP] MySQL Load - Konstantinos - 03.09.2013

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.


Re: [HELP] MySQL Load - shulk - 05.09.2013

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