title: PHP mysqli_connect not working but mysql_connect is working fine
body: <p>I'm trying to connect to a mysql database using mysql_connect and it fetches the desired result. However when I'm trying to fetch using mysqli_connect below error msg is shown:</p>
  
  <blockquote>
    <p>Access Denied for user "@"'localhost ' to database "tbl_name"</p>
  </blockquote>
  
  <p>Here is my Php code:</p>
  
  <p>db_connect.php</p>
  
  <pre><code>&lt;?php
  
  /**
   * A class file to connect to database
   */
  class DB_CONNECT {
  
      // constructor
      function __construct() {
          // connecting to database
          $this-&gt;connect();
      }
  
      // destructor
      function __destruct() {
          // closing db connection
          $this-&gt;close();
      }
  
      /**
       * Function to connect with database
       */
      function connect() {
          // import database connection variables
          require_once __DIR__ . '/db_config.php';
  
          // Connecting to mysql database
          //$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
          $con = mysqli_connect(DB_SERVER,DB_USER, DB_PASSWORD,DB_DATABASE);
  
          // Selecing database
          $db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
  
          // returing connection cursor
          return $con;
      }
  
      /**
       * Function to close db connection
       */
      function close() {
          // closing db connection
          mysql_close();
      }
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>getallimages.php</p>
  
  <pre><code>&lt;?php
  
  /*
   * Following code will list all the images
   */
  
  // array for JSON response
  $response = array();
  
  // include db connect class
  require_once __DIR__ . '/db_connect.php';
  
  // connecting to db
  $db = new DB_CONNECT();
  
  // get all products from products table
  $result = mysql_query("SELECT *FROM images_tbl") or die(mysql_error());
  
  // check for empty result
  if (mysql_num_rows($result) &gt; 0) {
      // looping through all results
      // products node
      $response["products"] = array();
  
      while ($row = mysql_fetch_array($result)) {
          // temp user array
          $product = array();
          $product["images_id"] = $row["images_id"];
          $product["images_path"] = $row["images_path"];
          $product["submission_date"] = $row["submission_date"];        
  
          // push single product into final response array
          array_push($response["products"], $product);
      }
      // success
      $response["success"] = 1;
  
      // echoing JSON response
      echo json_encode($response);
  } else {
      // no products found
      $response["success"] = 0;
      $response["message"] = "No products found";
  
      // echo no users JSON
      echo json_encode($response);
  }
  ?&gt;
  </code></pre>