title: mysql to mysqli conversion error
body: <p>this is my code was in mysql now i want to change as mysqli but getting an error.</p>
  
  <pre><code>$query = "SELECT COUNT(*) as totalCount FROM blog_posts";
          $rec = mysql_fetch_array(mysql_query($query));
          $total = $rec['totalCount'];
  </code></pre>
  
  <p>what I did</p>
  
  <pre><code>$query = "SELECT COUNT(*) as totalCount FROM blog_posts";
          $rec = mysqli_fetch_array(mysqli_query($link,$query));
          $total = $rec['totalCount'];
  </code></pre>
  
  <p>but the error i am getting that </p>
  
  <pre><code>Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\wamp\www\html\function.php on line 6
  
  Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\wamp\www\html\function.php on line 6
  
  Notice: Undefined variable: link in C:\wamp\www\html\function.php on line 6
  </code></pre>
  
  <p>dBconfig</p>
  
  <pre><code>&lt;?php
  $link=mysqli_connect("localhost","root","","blogdemo");
  // Check connection
  if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
  
  ?&gt;
  </code></pre>