PHP MySQL 连接数据库
<h3 style="color: black; text-align: left; margin-bottom: 10px;">PHP MySQL 连接数据库</h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_connect(servername,username,password);</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic4.zhimg.com/80/v2-1e5475159c778510dce0b7dcc687535b_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>
<div style="color: black; text-align: left; margin-bottom: 10px;"><?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die(Could not connect: . mysql_error());
}
// some code
mysql_close($con); // 需<span style="color: black;">即时</span>关闭?></div>
<h3 style="color: black; text-align: left; margin-bottom: 10px;">php<span style="color: black;">插进</span>数据到mysql</h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">按照</span>url传入的参数新增</p>例子<div style="color: black; text-align: left; margin-bottom: 10px;"><?php
$con = mysqli_connect("localhost", "root", ""); // <span style="color: black;">第1</span>个参数是<span style="color: black;">位置</span>, 第二个参数是用户名, 第三个参数是<span style="color: black;">暗码</span>if (!$con) // <span style="color: black;">倘若</span><span style="color: black;">无</span>被连接上
{
die(Could not connect: . mysqli_error($con)); // 就死掉
} else {
echo "mysql ok";
}
// some code// 操作完, <span style="color: black;">必须</span><span style="color: black;">即时</span>关闭数据库
mysqli_select_db($con,"phplesson");
// 定义sql语句
$sql="INSERT INTO `news` (`newstitle`, `newsimg`, `newscontent`, `addtime`) VALUES (newstitle, newsimg, newscontent, 2015-01-30)";
// 执行sql操作, 并接收返回值
$result = mysqli_query($con,$sql);
if (!$result)
{
die(Error: . mysqli_error($con));
}else{
echo "1 record added success";
}
mysqli_close($con);
?></div>
<h3 style="color: black; text-align: left; margin-bottom: 10px;">php删除mysql的数据</h3><span style="color: black;">按照</span>url传入的参数删除<div style="color: black; text-align: left; margin-bottom: 10px;"><?php// <span style="color: black;">按照</span>url传入的参数删除
$con = mysqli_connect("localhost", "root", ""); // <span style="color: black;">第1</span>个参数是<span style="color: black;">位置</span>, 第二个参数是用户名, 第三个参数是<span style="color: black;">暗码</span>if (!$con) // <span style="color: black;">倘若</span><span style="color: black;">无</span>被连接上
{
die(Could not connect: . mysqli_error($con)); // 就死掉
} else {
echo "mysql ok";
}
$newstitle = $_GET;
echo $newstitle;
// some code// 操作完, <span style="color: black;">必须</span><span style="color: black;">即时</span>关闭数据库
mysqli_select_db($con,"phplesson");
// 定义sql语句
$sql="DELETE FROM `news` WHERE newstitle=$newstitle";
// 执行sql操作, 并接收返回值
$result = mysqli_query($con,$sql);
if (!$result)
{
die(</div>
我深感你的理解与共鸣,愿对话长流。 你的话语如春风拂面,温暖了我的心房,真的很感谢。 你的见解独到,让我受益匪浅,非常感谢。 你的见解独到,让我受益匪浅,非常感谢。
页:
[1]