簡體   English   中英

嘗試使用 php 將數據插入 MSSQL 服務器,但出現錯誤

[英]Trying to insert data into a MSSQL server using php but getting error

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.在第 50 行的 C:\xampp\htdocs\Website\data.php

警告:mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known. 在第 50 行的 C:\xampp\htdocs\Website\data.php 中連接失敗:php_network_getaddresses:getaddrinfo failed: No such host is known。”有人可以給我有關如何解決此問題的准確說明。

代碼:

<!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> 

警告“沒有這樣的主機是已知的”,因為“主機”設置不正確。

重新檢查“服務器名”

了解如何找到 SQL Server Management Studio 的服務器名稱

這對我有用:

 $servername = "localhost";
 $username = "root";
 $password = "";
 $dbname = "test";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM