title: MySQL conditional user permissions
body: <p><strong>The question… Is it possible to add MySQL permissions to only allow to select fields based on permissions?</strong></p>
  
  <p>Example:</p>
  
  <ol>
  <li>User <code>user1</code> can only select/insert/delete from the <code>users</code> table where the column <code>instance</code> is equal to <code>1</code> (1 being passed via PHP).</li>
  <li>User <code>user2</code> can only select/insert/delete from the <code>users</code> table where the column <code>instance</code> is equal to <code>2</code> (1 being passed via PHP).</li>
  </ol>
  
  <p><strong>Here's the background info:</strong></p>
  
  <p>I'm creating an application with the same code base being used for multiple sites. Conditions within the app load different layouts. The multiple sites are using the same database because most information can be shared between sites. A user that registers on one site must also register on another site (this is how we want it because the sites are "by invitation only")</p>
  
  <p>What I'm thinking of doing is to have users table: id, email, password, instance. The instance column would have the id of the site.</p>
  
  <p>On the application layer every time I need to select/insert/delete from this table I append instance = [site_id] to the query... example: <code>SELECT * FROM users WHERE email = '' AND instance = [site_id];</code></p>