Well, I wrote this small code: [spoiler]function Store(){
local z = GetVehicleCount(), a = 1, ms = clock();
print("Started storing at: " + ms + " seconds.");
for( local veh, pos; a <= z; a++ ){
veh = FindVehicle(a);
if( !veh ) continue;
pos = veh.Pos;
mysql_query(dbGlobal, format( "INSERT INTO vehicles(id,model,world,x,y,z,angle,col1,col2) VALUES('%i','%i','%i','%f','%f','%f','%f','%i','%i')",
veh.ID,
veh.Model,
veh.World,
pos.x,
pos.y,
pos.z,
veh.GetRadiansAngle(),
veh.Colour1,
veh.Colour2
) );
print("Adding vehicle number: " + veh.ID + " to the database" );
}
print("Storing finished. Took: " + ( clock() - ms ) + " seconds." );
}
function CVehicle::GetRadiansAngle()
{
local angle = ::asin(this.Rotation.z) * -2;
return this.Rotation.w < 0 ? 3.14159 - angle : 6.28319 - angle;
}[/spoiler]
I can't find an error. I get the message that the things are successfully done.( last print thing ). But when I open phpmyadmin and see that table, then I see that's it's totally empty. Nothing gets added there. I can't even know why. I was trying to make those vehicles using a DB. So, I need this help now, can anybody help me sorting this things out? I would be glad if someone helps me and tells me the reason why it was not working.
Try the query as:
mysql_query(dbGlobal, format( "INSERT INTO vehicles(`id`,`model`,`world`,`x`,`y`,`z`,`angle`,`col1`,`col2`) VALUES(%d,%d,%d,%.2f,%.2f,%.2f,%.2f,%d,%d)",
veh.ID,
veh.Model,
veh.World,
pos.x,
pos.y,
pos.z,
veh.GetRadiansAngle(),
veh.Colour1,
veh.Colour2
) );
Try adding a print( mysql_error(dbGlobal) ) and see what it returns.
Quote from: Thijn on Feb 25, 2016, 06:44 PMTry adding a print( mysql_error(dbGlobal) ) and see what it returns.
Gotcha thanks! Problem solved!