Mysql在php中的应用

// 连接数据库
// $abc=new mysqli('localhost','root','root','对应的数据库名');
// $abc->query(sq语句);

// if($abc->connect_error){
//     die('连接失败'.'$abc->connect_error');
// }
// echo '连接成功';
// 断开连接
// $abc->close();
// echo $abc->error;获取错误信息;

$abc=new mysqli('localhost','root','root','edu');
// $aa='insert into score (stage,score,sid,tid) values ("2","100","2","6");
// insert into score (stage,score,sid,tid) values ("2","100","2","6");
// insert into score (stage,score,sid,tid) values ("2","100","2","6")';

// $aa='delete from score where id>=10';
// $aa='update score set stage =3 where id=5';

// $cc=$abc->query($aa);
// $cd=$cc->fetch_all(MYSQLI_ASSOC);  获取数组
// 
$aa='select*from student';
$cc=$abc->query($aa);
$cd=$cc->fetch_all(MYSQLI_ASSOC);
// var_dump($cd);
foreach($cd as $val){
    echo $val['name'].'<br>';
}

// 执行多条sql语句
// $res =$abc->multi_query($aa);

// $res=$abc->multi_query($aa);

posted on 2020-06-05 17:00  vermouthmo  阅读(129)  评论(0)    收藏  举报

导航