php 连接mysql数据库
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在navicat上创建student库,下面创建info表,表内填写信息id和name字段</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic1.zhimg.com/80/v2-579f4ba1ec25ee964ffac073889bb5b4_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">用phpstorm连接数据库并展示信息</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic2.zhimg.com/80/v2-cc44049e198f72f0f80883770d0bc0c9_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">//连接数据库</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">$con = mysqli_connect("localhost", "root", "root", "student", "8888");</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">if (mysqli_connect_error($con)) {</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> echo "连接失败" . mysqli_connect_error();</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">} else</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> echo "连接成功";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">//<span style="color: black;">查找</span>操作</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">$q = "select * from info";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">//添加、<span style="color: black;">插进</span>用户信息</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">//mysqli_query($con, "insert into info(id,name ) value (1006,heihei)");</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">$result = $con->query($q);</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">while ($row = mysqli_fetch_assoc($result)) {</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo "id: " . $row["id"] . " - Name: " . $row["name"] . "";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysqli_close($con)</p>?>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">浏览器中展示的效果</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic1.zhimg.com/80/v2-d0707cb266a7acd7f7b271e139f674bc_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
你的言辞如同繁星闪烁,点亮了我心中的夜空。 系统提示我验证码错误1500次 \~゛, 论坛的成功是建立在我们诚恳、务实、高效、创新和团结合作基础上,我们要把这种精神传递下去。 你的见解独到,让我受益匪浅,非常感谢。 楼主听话,多发外链好处多,快到碗里来!外链论坛 http://www.fok120.com/ i免费外链发布平台 http://www.fok120.com/
页:
[1]