title: Codeigniter SQL Injection
body: <p>I have this code on my controller:</p>
  
  <pre><code>$sql = "SELECT * FROM user WHERE id = " . $this-&gt;input-&gt;get('foo'); 
  $foo = $this-&gt;db-&gt;query($sql);
  echo '&lt;pre&gt;';
  print_r($foo-&gt;result());
  echo '&lt;/pre&gt;';
  die();
  </code></pre>
  
  <p>I've noticed that if I use this URL:<br>
  www.site.com?foo=1 OR 1 = 1<br>
  all data of the user table is shown:</p>
  
  <pre><code>Array
  (
  [0] =&gt; stdClass Object
      (
          [id] =&gt; 1
          [email] =&gt; aaa@gmail.com
          [password] =&gt; aaa
      )
  [1] =&gt; stdClass Object
      (
          [id] =&gt; 1
          [email] =&gt; bbb@gmail.com
          [password] =&gt; bbb
      )
  [2] =&gt; stdClass Object
      (
          [id] =&gt; 1
          [email] =&gt; ccc@gmail.com
          [password] =&gt; ccc
      )
  )
  </code></pre>
  
  <p>Is it possible to run another query that returns the data from the user_phone table?</p>
  
  <p><strong>Tables:</strong></p>
  
  <pre><code>CREATE TABLE `user` (
    `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
    `email` VARCHAR(100) NOT NULL,
    `password` VARCHAR(255) NOT NULL
    PRIMARY KEY (`id`),
  ) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
  
  
  CREATE TABLE `user_phone` (
    `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
    `id_user` INT(11) UNSIGNED NOT NULL,
    `number` INT(11) UNSIGNED NOT NULL
    PRIMARY KEY (`id`)
  ) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
  </code></pre>
  
  <p><strong>Data:</strong></p>
  
  <pre><code>INSERT  INTO `user`(`email`,`password`) VALUES ('aaa@gmail.com','aaa');
  INSERT  INTO `user`(`email`,`password`) VALUES ('bbb@gmail.com','bbb');
  INSERT  INTO `user`(`email`,`password`) VALUES ('ccc@gmail.com','ccc');
  
  INSERT  INTO `user_phone`(`id_user`,`number`) VALUES ('1','911911911');
  INSERT  INTO `user_phone`(`id_user`,`number`) VALUES ('1','922922922');
  INSERT  INTO `user_phone`(`id_user`,`number`) VALUES ('2','955955955');
  INSERT  INTO `user_phone`(`id_user`,`number`) VALUES ('3','711711711');
  </code></pre>
  
  <p>Thks</p>
  
  <p><strong>EDIT:</strong><br>
  I'm aware of the existing mechanisms to prevent this from happening.<br>
  My question is if it's possible, and how, can I get data from other tables.</p>