How can we connect to a MySQL database from a PHP script?

I have my php code like this to connect my server database

<?php
    $con=mysqli_connect("","username" ,"password","databasename");
    if (mysqli_connect_errno())
     {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
     }
     ?>

But it displayed "Failed to connect to MYSQL", what is wrong with this code?, first time i am trying it in web server, whereas my localhost worked perfectly. Anyone has some suggestion?

PHP Php Mysql
  • 0
  • 0

Give an Answer

Login to answer