Connecting to Database.

+5 Dhruv Singhal · June 8, 2016
Can anyone tell me that if my domain name is and i want to connect to my mySQL database so what will be the host name that is required in "mysql_connect" function

Post a Reply


Oldest  Newest  Rating
+1 pwntastic _ · June 9, 2016
I don't understand the first question.  Are you asking if your domain name is because it is not for kind of obvious reasons.(Ask yourself is this your website)

For your host name it can depend on how you have things set up.  If your script is on the same server that your database is on, you can use localhost or

If your database is on a different server, then you can use the ip address of that, or the domain name if dns is set up and what not.
0 Dhruv Singhal · June 13, 2016
thanks i got my answer i mentioned "" that if someone want to explain me with example.
0 Suman Banerjee · October 22, 2016
Sometimes, domain name and MySQL hostnames are different. If your hostname is, then the connect function would be something like this:

0 Ivar Karstensen · November 1, 2016
Sounds like the worst attempt on hacking, but I suggest PDO.
$pdo = false;

try {
    $pdo = new PDO('mysql:host=;dbname=yourdatabase', 'root', 'password');
} catch(PDOException $e) {
0 Muhammad Tahir Shaikh · November 13, 2016
useful one 

$var = new mysqli($localhost, $username, $password, $datebase");

if ($var->connect_error){
        die("Not Connected: " .$var-> connect_error";
  • 1



Server-side, HTML embedded scripting language used to create dynamic Web pages.