MySQL Selection fails
#1

I've talked about this error on my other topic, but I decided to post it as new one for few motivations:
-The old topic contains a title of problem that have been fixed
-This new topic with new name can be found by someone else that got my same problem

After that, here's my problem, I'm trying to make a Dynamic car system, I've made the DB, and every thing, when you buy the vehicle it run this query
pawn Код:
//Called on the command to create the Vehicle
format(query, sizeof(query), "INSERT INTO car(Owner, Model, Price, Col1, Col2, cLock, cX, cY, cZ, cA, tID) VALUES ('%s', '%d', '%d', '%d', '%d', '%d', '%f', '%f', '%f', '%f', '%d')",
                                        RUS(playerid), //Name w/out '_'
                                        model,
                                        price,
                                        Car[id][cCol1],
                                        Car[id][cCol2],
                                        Car[id][cLock],
                                        Car[id][cX],
                                        Car[id][cY],
                                        Car[id][cZ],
                                        Car[id][cA],
                                        id);
        print(query); // DEBUG
        mysql_function_query(connection, query, false, "", "");
It just works fine, I've checked the DB and no problem here
But then, I try to Select the information to take the SQLid (the unique ID) from tID (temp ID, taken from GetPlayerVehicleID)
With this query
pawn Код:
//Called when you press ENTER while chosing the colors of vehicle
new query[1024];
                format(query, sizeof(query), "SELECT * FROM car WHERE tID = '%d' LIMIT 1", GetPlayerVehicleID(playerid));
                mysql_function_query(connection, query, true, "SetPlate", "dd", playerid, GetPlayerVehicleID(playerid));
On SetPlate I do:
pawn Код:
new rows, fields;
cache_get_data(rows, fields);
if(rows)
{
    //Code here
}
else
{
   //ERROR MESSAGE Here
}
It always return no rows, but printing the query and just do a copy / paste to the SQL Executer it shows the line, without giving error...
Reply
#2

Check mysql_log to see what's going on.

And by the way, not sure, interger should not have single quotes...

PHP код:
"SELECT * FROM `car` WHERE tID = %d LIMIT 1" 
Reply
#3

Here's the log file
Код:
[16:54:01] [DEBUG] mysql_tquery - connection: 2, query: "SELECT * FROM `car` WHERE tID = 1 LIMIT 1", callback: "SetPlate", format: "dd"
[16:54:01] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[16:54:01] [DEBUG] mysql_tquery - scheduling query "SELECT * FROM `car` WHERE tID = 1 LIMIT 1"..
[16:54:01] [DEBUG] CMySQLQuery::Execute[SetPlate(dd)] - starting query execution
[16:54:01] [DEBUG] CMySQLQuery::Execute[SetPlate(dd)] - query was successful
[16:54:01] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[16:54:01] [DEBUG] CMySQLQuery::Execute[SetPlate(dd)] - data being passed to ProcessCallbacks()
[16:54:01] [DEBUG] Calling callback "SetPlate"..
[16:54:01] [DEBUG] cache_get_data - connection: 1
[16:54:01] [WARNING] cache_get_data - no active cache
Where's the error?
The caching is set to true...
Reply
#4

I've now tried to call SetPlate on the INSERT INTO query, and tried to get the SQLid by cache_insert_id();
but always return 0...
Reply
#5

Up, someone can help?
Reply
#6

Why you choosed to use this method?

mysql_function_query(connection, query, true, "SetPlate", "dd", playerid, GetPlayerVehicleID(playerid));

You did by some tutorial or just decided it will be better as this?


I would go as this:
(First off I wouldn't use GetPlayerVehicleID(playerid) for mysql, but would use a unique carid for DB, as if you change some cars IG, your whole table goes wasted. )

pawn Код:
new Plate[10],veh = GetPlayerVehicleID(playerid);
format(query, sizeof(query), "SELECT `Plate` FROM `car` WHERE `tID` = '%d'",veh );
mysql_query(query);
mysql_store_result();
mysql_fetch_field("Plate",Plate);
mysql_free_result();
SetVehicleNumberPlate(veh ,Plate);
Just for god sake don't use loop, if you use this method.
Reply
#7

I have follow no tutorial, This is going to be called when you create the vehicle. I know InGame ids changes, so i use it on another variable called tID (tempID) that set his value with the current id of vehicle, then get the SQLid generated by AI in SQL table by SELECT SQLid FROM car WHERE tID = GetPlayerVehicleID(playerid)
Now I'll try this method, and edit this message when I'll be done
Reply
#8

EDIT: Error fixed, Trying the code
Reply
#9

Tried and still not works, the problem seems to be that the query do not find rows, but if I try the SAME code in Phpmyadmin it works perfectly...
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)