gpt4 book ai didi

PHP 警告 : mysqli_close() expects parameter 1 to be mysqli

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:02:48 25 4
gpt4 key购买 nike

我正在尝试通过 php 连接到 sql 数据库,但一直收到我无法弄清楚的错误。我可以毫无错误地连接到另一个调试脚本。我获得连接并提取数据,但最后出现错误。

$con=mysqli_connect("localhost","username","password","dbname");

// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// This SQL statement selects ALL from the table 'Locations'
$sql = "SELECT * FROM Locations";

// Check if there are results
if ($result = mysqli_query($con, $sql))
{
// If so, then create a results array and a temporary one
// to hold the data
$resultArray = array();
$tempArray = array();

// Loop through each row in the result set
while($row = $result->fetch_object())
{
// Add each row into our results array
$tempArray = $row;
array_push($resultArray, $tempArray);
}

// Finally, encode the array to JSON and output the results
echo json_encode($resultArray);
}

// Close connections
mysqli_close($result);
mysqli_close($con);
?>

把这个拿出来

[{"Name":"Apple","Address":"1 Infinity Loop Cupertino, CA","Latitude":"37.331741","Longitude":"-122.030333"},{"Name":"Googleplex","Address":"1600 Amphitheatre Pkwy, Mountain View, CA","Latitude":"37.421999","Longitude":"-122.083954"}]

Warning: mysqli_close() expects parameter 1 to be mysqli, object given in /home/jfletch/public_html/appone/connect.php on line 36

最佳答案

mysqli_close($result);

上面这行是不正确的。您只需要调用 mysqli_close() 一次(如果有的话,正如评论中指出的那样,连接在脚本执行结束时关闭)并且参数应该是您的链接标识符,而不是您的查询资源。

删除它。

关于PHP 警告 : mysqli_close() expects parameter 1 to be mysqli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23282284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com