16.07.2017, 11:14
I am quite new to understanding the way mysql works as a whole. Especially Table structure and foreign keys, I've got a system with basically the exact same system as your explanation. However I'm not sure how to add to the table and also how to load from the table. Could someone please explain and show me how to do it? Thank you
PHP Code:
mysql_format(ServerMySQL,string,sizeof(string),"CREATE TABLE IF NOT EXISTS `Vehicles` (\
`uID` int(11) NOT NULL,\
`VehID` int(11) unsigned NOT NULL AUTO_INCREMENT,\
`Type` tinyint(7) NOT NULL DEFAULT '0',\
`Model` tinyint(7) NOT NULL DEFAULT '0',\
`Locked` tinyint(7) NOT NULL DEFAULT '0',\
`Fuel` tinyint(7) NOT NULL DEFAULT '0',\
`CarX` float NOT NULL,\
`CarY` float NOT NULL,\
`CarZ` float NOT NULL,\
`CarR` float NOT NULL,\
`VehNum` char(9) NOT NULL,");
mysql_format(ServerMySQL,string,sizeof(string),"%s\
`SavedWeaps0` tinyint(7) NOT NULL DEFAULT '0',\
`SavedAmmos0` tinyint(7) NOT NULL DEFAULT '0',\
`SavedWeaps1` tinyint(7) NOT NULL DEFAULT '0',\
`SavedAmmos1` tinyint(7) NOT NULL DEFAULT '0',\
`SavedWeaps2` tinyint(7) NOT NULL DEFAULT '0',\
`SavedAmmos2` tinyint(7) NOT NULL DEFAULT '0',",string);
mysql_format(ServerMySQL,string,sizeof(string),"%s\
`SavedWeaps3` tinyint(7) NOT NULL DEFAULT '0',\
`SavedAmmos3` tinyint(7) NOT NULL DEFAULT '0',\
`SavedWeaps4` tinyint(7) NOT NULL DEFAULT '0',\
`SavedAmmos4` tinyint(7) NOT NULL DEFAULT '0',\
PRIMARY KEY (`VehID`)) ENGINE = InnoDB DEFAULT CHARSET=latin1",string);
mysql_tquery(ServerMySQL, string);
mysql_tquery(ServerMySQL, "ALTER TABLE `Vehicles` ADD FOREIGN KEY (`uID`) REFERENCES `Users` (`uID`) ON UPDATE CASCADE ON DELETE CASCADE");
mysql_format(ServerMySQL,"CREATE TABLE IF NOT EXISTS `Vehicle_Mods` (\
`VehID` int(11) unsigned NOT NULL,\
`mod_model` smallint(5) unsigned NOT NULL,\
`Col1` tinyint(7) unsigned NOT NULL DEFAULT '0',\
`Col2` tinyint(7) unsigned NOT NULL DEFAULT '0',\
`CarPaint` smallint(7) unsigned NOT NULL DEFAULT '255',\
PRIMARY KEY (`VehID`, `mod_model`)) ENGINE = InnoDB DEFAULT CHARSET=latin1");
mysql_tquery(ServerMySQL, string);
mysql_tquery(ServerMySQL, "ALTER TABLE `Vehicle_Mods` ADD FOREIGN KEY (`VehID`) REFERENCES `Vehicles` (`VehID`) ON UPDATE CASCADE ON DELETE CASCADE");