title: How to use foreign keys with PHP
body: <p>So I understand how to create foreign keys and I know what is the purpose of the FK. But I have a problem in understanding How to use them. I asked a question regarding Foreign keys <a href="https://stackoverflow.com/questions/19741722/foreign-key-for-multiple-tables-and-columns">HERE(Click link)</a></p>
  
  <p>Here is what I made:</p>
  
  <pre><code>CREATE TABLE user(
    id INT(11) NOT NULL AUTO_INCREMENT,
    username VARCHAR(50) NOT NULL,
    password VARCHAR(20) NOT NULL,
    PRIMARY KEY (id)
  );
  
  CREATE TABLE items(
    i_id INT(11) NOT NULL AUTO_INCREMENT,
    name TINYTEXT NOT NULL,
    price DECIMAL(8,2) NOT NULL,
    PRIMARY KEY (i_id)
  );
  
  CREATE TABLE user_purchase(
    i_id INT(11) NOT NULL,
    name TINYTEXT NOT NULL,
    id INT(11) NOT NULL,
    FOREIGN KEY (i_id) REFERENCES items(i_id),
    FOREIGN KEY (name) REFERENCES items(name),
    FOREIGN KEY (id) REFERENCES user(id)
  );
  </code></pre>
  
  <p>Now my question is how do I make the most out of this using PHP? From the link above, people have suggested that it's good to use only one foreign key in the user_purchase table, but what if I want several columns? Why don't we use several foreign keys for different columns of the same table?</p>
  
  <p>I am using mysql and php. I would appreciate it if you could show some examples of how you use PHP with the tables which have foreign keys to get get information using MYSQL commands. I really need a thorough explanation.</p>
  
  <p>I also need to understand the terms Normalization and Denormalization. I would appreciate if you could give some links which explain these terms in great detail with examples or if you have any suggestion for some great books for beginners in database design, implementation, etc, I would really appreciate.</p>
  
  <p>Thanks a lot.</p>