0

So i just bought a Microsoft azure SQL server, and im trying to connect to it using php on my website however it keeps throwing an error saying "Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\Website\data.php on line 50

Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\Website\data.php on line 50 Connection failed: php_network_getaddresses: getaddrinfo failed: No such host is known." Can someone give me precise instructions on how to fix this issue.

CODE:

<!DOCTYPE html>
<html>
<body>

<?php

$firstname = $_POST["inputFirstName"];

$lastname = $_POST["inputLastName"];

$email = $_POST["emailaddress"];
//$email = "";

$discordid = $_POST["discordid"];

$stuff = array($firstname, $lastname, $email, $discordid);
//echo implode(" ",$stuff);

require_once('vendor/autoload.php');
$stripe = new \Stripe\StripeClient(
  'APIKEYHERE'
);
if(!empty($stripe->customers->all(['email' => $email, 'limit' => 1])->data[0])){
$yo = $stripe->customers->all(['email' => $email, 'limit' => 1])->data[0]->id;
echo("You are already in our system your customer ID is: " . $yo);
}
else{
  echo("All good");
  
  $stripe->customers->create([
      'name' => $firstname . " " . $lastname,
      'email' => $email, 
    'description' => $discordid,
  ]);
  //add free subscription
  $stripe->subscriptions->create([
    'customer' => $stripe->customers->all(['email' => $email, 'limit' => 1])->data[0]->id,
    'items' => [
      ['price' => ''],
    ],
  ]);

  // Create connection
  $servername = "";
  $username = "";
  $password = "";
  $dbname = "";
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
  }
  
  $sql = "INSERT INTO tblCustomer (DiscordID, CustID, DiscordName)
  VALUES ('111', '55', 'John Smith')";
  
  if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
  } else {
    echo "Error: " . $sql . "<br>" . $conn->error;
  }
  
  $conn->close();

  //create and redirect user to billing session
  header("Location: ".$stripe->billingPortal->sessions->create([
    'customer' => $stripe->customers->all(['email' => $email, 'limit' => 1])->data[0]->id,
    'return_url' => 'https://www.google.com/',
  ])->url);
  }
?>
</body>
</html> 
RAT
  • 121
  • 1
  • 14
  • For the time being im just trying to do a get request, just to make sure i can get this going. – RAT Jul 29 '20 at 20:48
  • after your insert.. you have three = signs... shouldn't that be only 2 like == – Harry Jul 30 '20 at 03:16
  • @harry idk i copied that template from the internet. Ill give it a shot tho. – RAT Jul 30 '20 at 03:35
  • nope still doesnt work. ERROR: Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\Website\data.php on line 50 Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\Website\data.php on line 50 Connection failed: php_network_getaddresses: getaddrinfo failed: No such host is known. – RAT Jul 30 '20 at 03:37
  • I'm guessing.. where it says //creta connection . you have actually entered all your connections setting and not blank? Just asking the obvious! – Harry Jul 30 '20 at 03:39
  • Yes i have entered all my connection settings – RAT Jul 30 '20 at 03:47
  • I feel like it has to do with these dumb drivers. – RAT Jul 30 '20 at 03:47

1 Answers1

1

Warning "No such host is known" occur because "Host" is not set properly.

Recheck the 'servername'

To know about How to find server name of SQL Server Management Studio

This worked for me :

 $servername = "localhost";
 $username = "root";
 $password = "";
 $dbname = "test";
Yashit Sahni
  • 116
  • 1
  • 2