xampp+phpmyadmin
下午不知道为什么,装的xampp打不开mysql了,怎么弄都不行,重装了一下,就好了。。。
然后localhost 就是那个首页
打开phpmyadmin
新建数据库
插入
phpmyadmin - mysql - user - 找到主机名 用户 密码
<?php
//连接数据库
$conn = new mysqli("localhost","root","","phpcrud");
if($conn->connect_error){
die("could not connect to database.");
}
if(isset($_GET['action'])){ //这个获取到的是url ?后面action=..的内容 isset:存在
echo $_GET['action'];
}
?>
echo json_encode($res);
//我这个报错了,显示
所以我改了一下
$conn = mysqli_connect("localhost", "root", "", "phpcrud");
// Check connection
if (!$conn) {
die("连接失败: " . mysqli_connect_error());
}else{
echo "连接成功";
}
$sql = "SELECT id, username, email FROM users";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// 输出数据
while($row = mysqli_fetch_assoc($result)) {
echo "id: " . $row["id"]. " - Name: " . $row["username"]. " " . $row["email"]. "<br>";
}
} else {
echo "0 结果";
}
mysqli_close($conn);