Database change search method deletions

database

Rapid implementation in the database

search information

SELECT * FROM `user`

Queries username table of contents

select username from `user`

To insert the contents of the database user table

INSERT INTO `wui1611(表名)`.`user(字段)` (`id`, `username`, `pass`) VALUES ('1', 'zhangsan','1234'), ('2', 'lisi', '123456'); 

Modify the contents of the table

UPDATE `wui1611`.`user` SET `pass` = '1234' WHERE `user`.`id` = 1;

Delete table of contents

“DELETE FROM `wui1611`.`user` WHERE `user`.`id` = 1”

php file write

Delete lines

  • Transfer array delete id in { ''}

Link Database

$link=mysqli_connect('localhost','root','','wui1611',3306);//链接数据库(主机名 用户名 密码 数据库名 端口号可省)

The encoded into unicode utf8 format

mysqli_set_charset($link,'utf8');

search information

$sql="select * from student";//获取student表里的所有信息

Request

$result=mysqli_query($link,$sql);//发出请求

Format the result set into MYSQL_ASSOC

$arr=mysqli_fetch_all($result,MYSQL_ASSOC);//结果集转换为MYSQL_ASSOC格式

modify

$sql="update student set {$attr}='{$values}' where id='{$ids}'";//修改id为ids的attr的内容为values

Insert a row

$sql="insert into student (`name`,`age`,`sex`,`classes`,`jg`) values('','','','','')";

delete

$sql="delete from student where id='{$ids}'";//删除student表里id等于ids的这一行

The number of rows affected

$len=mysqli_affected_rows($link);//影响的行数

return value

$len=mysqli_insert_id($link);//返回删除这行的的id

Guess you like

Origin www.cnblogs.com/liuxuhui/p/12157246.html