title: sqlite2 to sqlite3 convert php code
body: <p>I'm trying to run a script on my server. This script uses sqlite2 as database. The php file is written in sqlite2, but on my server I have installed sqlite3.</p>
  
  <p>This is my code:</p>
  
  <pre><code>if (!$db = sqlite_open ('chatdb'))
  {
      die('Database problem. Please try again later.');
  }
  
  function sqlite_table_exists ($db, $mytable)
  {
      $result = sqlite_query($db, "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='$mytable'");
      $count = intval(sqlite_fetch_single($result));
      return $count &gt; 0;
  }
  
  if (sqlite_table_exists($db, 'messages') == false)
  {
      $sql = 'CREATE TABLE messages (username VARCHAR(50), message TEXT, date DATE)';
      sqlite_query ($db, $sql);
  }
  
  if (sqlite_table_exists($db, 'users') == false)
  {
      $sql = 'CREATE TABLE users (username VARCHAR(50) UNIQUE, last_activity DATE, is_kicked INTEGER DEFAULT 0, is_banned INTEGER DEFAULT 0, kick_ban_message VARCHAR(100))';
      sqlite_query ($db, $sql);
  }
  
  if (sqlite_table_exists($db, 'bans') == false)
  {
      $sql = 'CREATE TABLE bans (ip VARCHAR(15), time DATE)';
      sqlite_query ($db, $sql);
  }
  </code></pre>
  
  <p>When I run the code, I get errors, such as;</p>
  
  <pre><code>Fatal error: Call to undefined function sqlite_open()
  </code></pre>
  
  <p>I think the code is not ready for sqlite3. How can I convert this code to sqlite3?</p>
  
  <p>Thanks.</p>