- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有代码试图将从两个传感器读取的数据上传到 arduino 到 WAMP 服务器但是当运行 localhost\project 时,我收到警告。php 文件位于项目目录中。Connect.php访问数据库时使用。Connect.php 代码是主要用于连接的代码,add.php 处理来自 arduino.index.php 的 POST,在表格中显示传感器值:
下面是Connect.php
****<?php
function Connection(){
$server="server";
$user="user";
$pass="pass";
$db="database";
$connection = mysqli_connect($server, $user, $pass);
//$db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'user', 'pass');
if (!$connection) {
die('MySQL ERROR: ' . mysql_error());
}
mysql_select_db($db) or die( 'MySQL ERROR: '. mysql_error() );
return $connection;
}
?>****
下面是add.php:
**<?php
include("connect.php");
$link=Connection();
$temp1=$_POST["temp1"];
$hum1=$_POST["hum1"];
$query = "INSERT INTO `tempLog` (`temperature`, `humidity`)
VALUES ('".$temp1."','".$hum1."')";
mysql_query($query,$link);
mysql_close($link);
header("Location: index.php");
?>**
最后是 index.php:
**<?php
include("connect.php");
$link=Connection();
$result=mysql_query("SELECT * FROM `tempLog` ORDER BY `timeStamp` DESC",$link);
?>
<html>
<head>
<title>Sensor Data</title>
</head>
<body>
<h1>Temperature / moisture sensor readings</h1>
<table border="1" cellspacing="1" cellpadding="1">
<tr>
<td> Timestamp </td>
<td> Temperature 1 </td>
<td> Moisture 1 </td>
</tr>
<?php
if($result!==FALSE){
while($row = mysql_fetch_array($result)) {
printf("<tr><td> %s </td><td> %s </td><td> %s </td></tr>",
$row["timeStamp"], $row["temperature"], $row["humidity"]);
}
mysql_free_result($result);
mysql_close();
}
?>
</table>
</body>
</html>**
最佳答案
你错过了 mysqli_和 mysql_ (这不是一回事..)
连接返回一个 mysqli_
连接:
$connect = mysqli_connect($server, $user, $pass);
但是您正在尝试使用它来选择数据库并通过 mysql_
进行查询:
mysql_select_db($db) or die( 'MySQL ERROR: '. mysql_error() );
此外,使用 mysqli_
连接作为到 mysql_
查询的链接是没有意义的:
$link=Connection();
$result=mysql_query("SELECT * FROM `tempLog` ORDER BY `timeStamp` DESC",$link);
请看一下mysqli docs并抓取 mysql_
代码。 -- 或者更好,使用 PDO !
关于php - 警告 : mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28216910/
我目前正在升级我们的软件以支持 ipv6,同时我正在将主机名/ip 字段扩展到最大主机名大小。在 sun 文档中,它似乎可以达到 1025(netdb.h:#define NI_MAXHOST 102
我正在使用 docker-compose 为开发人员提供技术栈 ROR、postgres、redis、mongo 的开发环境。 docker-compose build 运行成功,但是当我运行 doc
nc -zv cms-01 5061 失败: nc: getaddrinfo: 没有与主机名关联的地址 但是 ping/dig 工作正常。用getent可以看到最不一样的地方: # getent ho
我正在测试一条错误路径,该路径要求我删除来自 getaddrinfo 的请求。我设置了 2 个虚拟机: RHEL 7.9 Ubuntu 20 代码在两台机器上是相同的,只是为 test.com 调用
当我调用 getaddrinfo与 AF_UNSPEC ,理论上它可以返回任何它喜欢的地址族:AF_INET , AF_INET6 ,也许是 AppleTalk、蓝牙、datalink、netlink
我花了几个小时试图找出我的问题,只是在我写问题的时候找到了解决方案(当你需要正式化你的问题并解释它时,它总是有帮助的)。我发布它,希望它可以帮助某人。 使用 getaddrinfo,如果我尝试将套接字
我尝试通过给 getaddrinfo 赋予 http(s) 前缀来使用它,但它无法正确查找主机。我该如何解决这个问题。我要查 https://www.google.com但 gai_strerror(
我想在我的 header 中定义一个端口号(例如 #define port 9191 )并使用它来调用 getaddrinfo() 。但我收到错误,因为参数服务是 char const* 。如何使用#
我对 getaddrinfo() 的行为有疑问,这似乎取决于服务参数的指定方式。将服务指定为名称会导致 getaddrinfo() 使用 getservbyname() 来查询/etc/service
我有一个程序(用 C 语言编写),它使用 getaddrinfo() ,它的第一个参数是我希望它获取地址信息的主机名,假设它是“域”。在同一台计算机上的 /etc/hosts 文件中,我可以看到“do
int print_socket_info(int sock_fd, struct sockaddr_in *sin, short protocol){ char dbg[INET_ADDRS
这个问题已经存在: Login and Registration in Android with PHP, MySQL and SQLite 已关闭 7 年前。 我正在尝试连接到我的 mysql wa
我想连接sql数据库。我究竟做错了什么?请帮忙 常量.php 连接.php 最佳答案 首先,您的 constants.php 文件似乎在开始的 PHP 标记中有错字。您应该按如下方式更新文件:
我目前正在尝试编写自己的 HTTP 代理。我的代码可以正常工作,但我尝试使用 ApacheBench 对其进行压力测试,发现时不时地收到如下消息: “getaddrinfo:提供了节点名或服务名,或者
我正在使用 getaddrinfo() API 来解析跨平台 C++ 应用程序中的 DNS 查询。我需要知道 getaddrinfo() 在不同平台上的时间成本?谁能帮我解决这个问题? 最佳答案 这个
我有一个使用套接字的程序。在客户端,我通过 getaddrinfo 获取必要的信息,然后将结果传递给连接函数。事情是,它在不同的环境中工作不同。在获取 addrinfo 结构并将其传递给 connec
我有一个网络地址,例如 - 192.168.74.0/24。尝试使用 getaddrinfo 获取网络地址转换似乎不起作用。这里的名称是 192.168.74.0/24。 getaddrindo 的返
所以我花了一段时间才弄明白,因为“段错误”没有显示任何代码行,但显然这会导致我的程序出现段错误: if (getaddrinfo(options.servername, (char *)options
我遇到了一个奇怪的问题。我有这个 Python 应用程序,当我尝试在应用程序中打开 url 时,例如 urllib2.urlopen("http://google.com", None) 我收到以下错
我在 LAN 中用于某些套接字通信应用程序的目标机器具有用于 IPv4 的 192.168.98.91。 当我尝试使用 getaddrinfo() 解析 IP 地址时,它返回 127.0.0.1 如何
我是一名优秀的程序员,十分优秀!