NcDreamy
NcDreamy

Reputation: 805

Trouble Connecting to the MySQL server

I'm trying to connect to the MySQL server using MySQLi. It is enabled in the server end where this code runs. I am unable to connect to the server using the following information. Did I miss something? Any help would be appreciated. Thank you.

<?php
        // DBInfo
        $hostname = "localhost";
        $username = "nc5ff";
        $password = "Ni\$hant809472";
        $dbname = "test";

        // DB Connection
        $link = mysqli_connect($hostname, $username, $password, $dbname);

        /* check connection */
        if (!$link) {
            header("Connection Failure", true, 777);
        }

        mysqli_close($link);

?>

Upvotes: 2

Views: 59

Answers (2)

maxhb
maxhb

Reputation: 8855

You have to escape the password as it contains special php characters (\ and $):

$password = "Ni\\\$hant809472";

Upvotes: 1

lyndact
lyndact

Reputation: 1

Make sure you have all of the information right i don't see anything wrong with the code, but please make sure you have all the information right.

Upvotes: 0

Related Questions