title: How to encrypt a specific column in a MySQL table?
body: <p>I am experimenting with creating a simple message system (PHP) page that uses a MySQL table to store the entries. The rough outline of the columns I'll use in the table are:</p>
  
  <p><strong>msg_id</strong> (primary key, auto_increment)</p>
  
  <p><strong>user_id</strong> (foreign key pointing to the user who created the message)</p>
  
  <p><strong>time</strong> (a DATETIME entry to provide msg timestamps)</p>
  
  <p><strong>msg</strong> (a VARCHAR containing the msg)</p>
  
  <p><strong>accessable</strong> (just an int(1), 0 means no one except the user himself can read the msg, and 1 means others can read it)</p>
  
  <p>What I'm wondering is, what's the best way to encrypt the <strong>msg</strong> field so prying eyes can't read it (let's say, by opening the mysql CLI or phpMyAdmin and just read the value stored in a row)?</p>
  
  <p>If "accessable" is set to 0, then only the user him/herself should be able to read it (by accessing some PHP page), but if set to 1, everyone else should be able to read it as well. I don't know how to tackle this, so any help is very appreciated!</p>