title: How to use function to connect to database and how to work with queries?
body: <p>I am using functions to work with database.. Now the way i have defined the functions are as follows:-</p>
  
  <pre><code>/**
   * Database definations
   */
  define ('db_type', 'MYSQL');
  define ('db_host', 'localhost');
  define ('db_port', '3306');
  define ('db_name', 'database');
  define ('db_user', 'root');
  define ('db_pass', 'password');
  define ('db_table_prefix', '');
  </code></pre>
  
  <hr>
  
  <pre><code>/**
   * Database Connect
    */
  function db_connect($host = db_host, $port = db_port, $username = db_user, $password = db_pass, $database = db_name) {
      if(!$db = @mysql_connect($host.':'.$port, $username, $password)) {
          return FALSE;
      }
      if((strlen($database) &gt; 0) AND (!@mysql_select_db($database, $db))) {
          return FALSE;
      }
      // set the correct charset encoding
      mysql_query('SET NAMES \'utf8\'');
      mysql_query('SET CHARACTER_SET \'utf8\'');
      return $db;
  }
  </code></pre>
  
  <hr>
  
  <pre><code>/**
   * Database Close
    */
  function db_close($identifier) {
      return mysql_close($identifier);
  }
  </code></pre>
  
  <hr>
  
  <pre><code>    /**
   * Database Query
    */
  function db_query($query, $identifier) {
      return mysql_query($query, $identifier);
  }
  </code></pre>
  
  <p>Now i want to know whether it is a good way to do this or not.....</p>
  
  <p>Also, while database connect i am using</p>
  
  <pre><code>$host = db_host
  </code></pre>
  
  <p>Is it ok? Secondly how i can use these functions, these all code is in my <strong>FUNCTIONS.php</strong> The Database Definitions and also the Database Connect... will it do the needful for me...</p>
  
  <p>Using these functions how will i be able to connect to database and using the query function... how will i able to execute a query?</p>
  
  <hr>
  
  <p><strong>VERY IMPORTANT</strong>: How can i make mysql to mysqli, is it can be done by just adding an '<strong><em>i</em></strong>' to mysql....Like:-</p>
  
  <pre><code>@mysql_connect
  </code></pre>
  
  <hr>
  
  <pre><code>@mysqli_connect
  </code></pre>