码迷,mamicode.com
首页 > 数据库 > 详细

吴裕雄--天生自然 PHP开发学习:MySQL子句

时间:2019-05-31 16:38:56      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:erro   connect   sqli   name   ase   span   col   nec   pass   

<?php
$con=mysqli_connect("localhost","username","password","database");
// 检测连接
if (mysqli_connect_errno())
{
    echo "连接失败: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM Persons ORDER BY age");

while($row = mysqli_fetch_array($result))
{
    echo $row[‘FirstName‘];
    echo " " . $row[‘LastName‘];
    echo " " . $row[‘Age‘];
    echo "<br>";
}

mysqli_close($con);
?>
<?php
$con=mysqli_connect("localhost","username","password","database");
// 检测连接
if (mysqli_connect_errno())
{
    echo "连接失败: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM Persons
WHERE FirstName=‘Peter‘");

while($row = mysqli_fetch_array($result))
{
    echo $row[‘FirstName‘] . " " . $row[‘LastName‘];
    echo "<br>";
}
?>
<?php
$con=mysqli_connect("localhost","username","password","database");
// 检测连接
if (mysqli_connect_errno())
{
    echo "连接失败: " . mysqli_connect_error();
}

mysqli_query($con,"UPDATE Persons SET Age=36
WHERE FirstName=‘Peter‘ AND LastName=‘Griffin‘");

mysqli_close($con);
?>
<?php
$con=mysqli_connect("localhost","username","password","database");
// 检测连接
if (mysqli_connect_errno())
{
    echo "连接失败: " . mysqli_connect_error();
}

mysqli_query($con,"DELETE FROM Persons WHERE LastName=‘Griffin‘");

mysqli_close($con);
?>

 

吴裕雄--天生自然 PHP开发学习:MySQL子句

标签:erro   connect   sqli   name   ase   span   col   nec   pass   

原文地址:https://www.cnblogs.com/tszr/p/10955787.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!