title: PHP MySQL database class not working with insertion
body: <p>I've been using this class:</p>
  
  <pre><code>&lt;?
  class DbConnector {
  
  var $theQuery;
  var $link;
  
  function DbConnector() {
  
      $host = 'localhost';
      $db = 'my_db';
      $user = 'root';
      $pass = 'password';
  
      // connect to the db
      $this-&gt;link = mysql_connect($host, $user, $pass);
      mysql_select_db($db);
      register_shutdown_function(array(&amp;$this, 'close'));
  }
  
  function find($query) {
      $ret = mysql_query($query, $this-&gt;link);
      if (mysql_num_rows($ret) == 0)
          return array();
      $retArray = array();
  
      while ($row = mysql_fetch_array($ret))
          $retArray[] = $row;
  
      return $retArray;
  }
  
  function insert($query) {
      $ret = mysql_query($query, $this-&gt;link);
  
      if (mysql_affected_rows() &lt; 1)
          return false;
      return true;
  }
  
  function query($query) {
      $this-&gt;theQuery = $query;
      return mysql_query($query, $this-&gt;link);
  }
  
  // get some results
  function fetchArray($result) {
  
      return mysql_fetch_array($result);
  }
  
  function close() {
      mysql_close($this-&gt;link);
  }
  
  function exists($query) {
      $ret = mysql_query($query, $this-&gt;link);
      if (mysql_num_rows($ret) == 0)
          return false;
  }
  
  function last_id($query) {
      return mysql_insert_id($query);
  }
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>Which I'm using for a lot of queries and it's working fine, although I'm trying to insert using this query:</p>
  
  <pre><code>    global $db;
          $query = $db-&gt;insert("INSERT INTO  `submissions` (
           `id` ,
          `quote` ,
          `filename` ,
          `date_added` ,
          `uploaded_ip`
          )
      VALUES (
      NULL ,  '{$quote}',  '{$filename}',  NOW(),  '{$_SERVER['REMOTE_ADDR']}')
      ");
  </code></pre>
  
  <p>And it's giving me this error:</p>
  
  <pre><code>Not Found
  
   The requested URL /horh_new/id/&lt;br /&gt;&lt;b&gt;Fatal error&lt;/b&gt;: Call to a member function        insert() on a non-object in &lt;b&gt;/Applications/MAMP/htdocs/horh_new/addit.php&lt;/b&gt; on line &lt;b&gt;52&lt;/b&gt;&lt;br /&gt; was not found on this server.
  </code></pre>
  
  <p>Although when I don't use that class above, and use this instead:</p>
  
  <pre><code>$con = mysql_connect("localhost","root","password");
   if (!$con) {
     die('Could not connect: ' . mysql_error());
     }
  
   mysql_select_db("my_db", $con);
  
   mysql_query("INSERT INTO  `submissions` (
           `id` ,
          `quote` ,
          `filename` ,
          `date_added` ,
          `uploaded_ip`
          )
      VALUES (
      NULL ,  '{$quote}',  '{$filename}',  NOW(),  '{$_SERVER['REMOTE_ADDR']}')
      ");
  
   echo mysql_insert_id();
  
   mysql_close($con);
  </code></pre>
  
  <p>It works fine. Can anyone tell me what is wrong with my class? I'd really appreciate it.</p>