PHP 7 连接MySQL,增删改查

发表于 2019-03-04   |   分类于 Mysql

查询
现在我在mysql中创建了school数据库,school中有student表,为了方便,表中只有id,name这两个字段

$conn = new mysqli("localhost", "root", "Sj1314", "school");
if ($conn != null) {
    $query_result = $conn->query("select * from student");
    while ($row = $query_result->fetch_row()) {
        var_dump($row);
    }
    $conn->close();
}


fetch_row()每次取一行数据,返回值类型是array;
增删改

$conn->query(" insert into student values(3,'王五')");
$conn->query(" insert into student values(4,'test')");
$conn->query(" update student set name ='php' where id=4");
$conn->query("delete from student where id=3 or id=4");
© 2019 Powered by Typecho & Theme Quark