Connecting to Database.

+5 Dhruv Singhal · June 8, 2016
Can anyone tell me that if my domain name is thenewboston.com 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

Replies

Oldest  Newest  Rating
+1 pwntastic _ · June 9, 2016
I don't understand the first question.  Are you asking if your domain name is thenewboston.com 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 127.0.0.1

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 "thenewboston.com" 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 thenewboston.com, then the connect function would be something like this:

mysqli_connect("thenewboston.com","user","pass","DatabaseName",3306);
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=127.0.0.1;dbname=yourdatabase', 'root', 'password');
} catch(PDOException $e) {
      die($e->getMessage();
}
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

PHP

131,177 followers
About

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

Links
Moderators