singh_designer singh_designer - 1 year ago 131
PHP Question

mysqli_select_db() ERROR, Database couln't connect

Hi I'm new to PHP and i coded a php page and created a database. I tried to connect db but it's not connecting.

$uname = "root";
$pwd = "";
$hostn = "localhost";

//connection to the database
$mysqlconn = mysqli_connect($hostn, $uname, $pwd)
or die("Unable to connect to MySQL");

//select a database to work with
$dbselect = mysqli_select_db("dataforuse",$mysqlconn)
or die("Could not select dataforuse");

This is what i get

Answer Source

Hi Try to debug and echo bugs in connection with mysqli_error() function.

    $uname = "root";
    $pwd = "";
    $hostn = "localhost"; 

    //connection to the database

        $mysqlconn = mysqli_connect($hostn, $uname, $pwd) or die(mysqli_connect_error());


      $mysqlconn = mysqli_connect($hostn, $uname, $pwd , $database) or die(mysqli_connect_error());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download