title: MySQL - Saving and loading
body: <p>I'm currently working on a game, and just a while ago i started getting start on loading and saving.</p>
  
  <p>I've been thinking, but i really can't decide, since I'm not sure which would be more efficient.</p>
  
  <p>My first option: 
  When a user registers, only the one record is inserted (into 'characters' table). When the user tries to login, and after he/she has done so successfully, the server will try loading all information from the user (which is separate across multiple tables, and combines via mysql 'LEFT JOIN'), it'll run though all the information it has and apply them to the entity instance, if it runs into a NULL (which means the information isn't in the database yet) it'll automatically use a default value. 
  At saving, it'll insert or update, so that any defaults that have been generated at loading will be saved now.</p>
  
  <p>My second option:
  Simply insert all the required rows at registration (rows are inserted when from website when the registration is finished).</p>
  
  <p>Downsides to first option: useless checks if the user has logged in once already, since all the tables will be generated after first login.</p>
  
  <p>Upsides to first option: if any records from tables are deleted, it would insert default data instead of kicking player off saying it's character information is damaged/lost.</p>
  
  <p>Downsides to second option: it could waste a bit of memory, since all tables are inserted at registration, and there could be spamming bots, and people who don't even manage to get online.</p>
  
  <p>Upsides to first option: We don't have to check for anything in the server.</p>
  
  <p>I also noted that the first option may screw up any search systems (via admincp, if we try looking a specific users).</p>