【问题标题】:Trying to insert data into a MSSQL server using php but getting error尝试使用 php 将数据插入 MSSQL 服务器但出现错误
【发布时间】:2020-11-19 13:10:29
【问题描述】:

所以我刚买了一个 Microsoft azure SQL 服务器,我试图在我的网站上使用 php 连接到它,但是它一直抛出一个错误,说“警告:mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: No such host已知。在 C:\xampp\htdocs\Website\data.php 第 50 行

警告:mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: 不知道这样的主机。在第 50 行的 C:\xampp\htdocs\Website\data.php 连接失败:php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。”有人可以给我有关如何解决此问题的准确说明。

代码:

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

【问题讨论】:

  • 目前我只是尝试做一个获取请求,只是为了确保我能做到这一点。
  • 在插入之后......你有三个 = 符号......不应该只有 2 个像 ==
  • @harry idk 我从互联网上复制了该模板。我会试一试。
  • 不行还是不行。错误:警告:mysqli::__construct():php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。在 C:\xampp\htdocs\Website\data.php 第 50 行警告:mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known.在 C:\xampp\htdocs\Website\data.php 第 50 行连接失败:php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。
  • 我猜.. 它在哪里说 //creta connection 。您实际上已经输入了所有连接设置而不是空白?只问显而易见的!

标签: php mysql sql-server tsql


【解决方案1】:

由于未正确设置“主机”而出现“未知主机”警告。

重新检查“服务器名称”

了解 How to find server name of SQL Server Management Studio

这对我有用:

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

【讨论】:

    猜你喜欢
    • 2021-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-04
    • 2017-10-13
    • 2011-01-12
    • 2016-08-18
    相关资源
    最近更新 更多