Php 连接到显示mysqli_connect()函数警告的数据库时出现问题

Php 连接到显示mysqli_connect()函数警告的数据库时出现问题,php,mysql,Php,Mysql,大家好,我正在学习php和mysql,因为这是我的激情, 经常面临连接数据库的问题 现在我的xampp不工作了,idk为什么apache没有启动,所以我最终安装了wamp服务器,并且localhost通过端口8080访问,使其可以作为localhost:8080”进行浏览,但当我键入as时它不工作 <?php $con = mysqli_connect("localhost:8080", "root", "", "social");//connection variable if(

大家好,我正在学习php和mysql,因为这是我的激情, 经常面临连接数据库的问题

现在我的xampp不工作了,idk为什么apache没有启动,所以我最终安装了wamp服务器,并且localhost通过端口8080访问,使其可以作为localhost:8080”进行浏览,但当我键入as时它不工作

<?php
 $con = mysqli_connect("localhost:8080", "root", "", "social");//connection variable   
if(!$conn){ 

echo "Failed to connect! " . mysqli_connect_errno();
 } 

$query = mysqli_query($con, "INSERT INTO test VALUES('1', 'thing')");

?>

语法

mysqli_connect(主机、用户名、密码、数据库名)


端口未指定为主机参数的一部分,而是指定为第5个参数。也就是说,MySQL的默认端口是3306,而端口8080是HTTP替代端口(默认为80)

或者,如果要指定端口,则

$con = mysqli_connect("localhost", "root", "", "social", 3306);
请参阅文档和以下链接:


另外,您的代码中有一个轻微的输入错误

if(!$conn){ 

正在使用错误的变量名(
$con
!=
$conn

尝试从wamp服务器托盘图标重新启动mysqli模块
$con = mysqli_connect("localhost", "root", "", "social", 3306);
if(!$conn){