您的位置:首页 > 数据库 > MySQL

php实现mysql数据的增删改查代码

2017-06-19 18:00 871 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

</head>

<?php

 

$conn=mysql_connect("127.0.0.1","root","") or die("连接不成功");//连接数据库

mysql_query("create database six",$conn)//新建数据库;

mysql_select_db("six",$conn);//选择操作的数据库

/*mysql_query("rename table school to teacher");//重命名

*/

//写sql最好先自己写纸上,再敲进去,容易错思路窄

//用··号,不区分大小写

/*

mysql_query("CREATE TABLE IF NOT EXISTS `student4` (

`id`int(11) NOT NULL auto_increment,

`name` varchar(255) NOT NULL,

`sex` varchar(2) NOT NULL,

`age` int(2) NOT NULL,

PRIMARY KEY(`id`))

ENGINE=innodb default charset=latin1 AUTO_INCREMENT=10;");//这里最是易错,有错误不执行。表,键名要用``,元素要用'',不一样的符号,用错了就不执行 

 /*

mysql_query("CREATE TABLE IF NOT EXISTS `teacher` (

  `id` int(16) NOT NULL auto_increment,

  `name` varchar(255) NOT NULL,

  `remarke` text character set gb2312 NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;");

 

 

 mysql_query("insert into `student4`(`id`,`name`,`sex`,`age`)

 VALUES

 (1,'xie','m',20),

 (2,'wangl','f',20),

 (3,'mang','m',20);");//表明项目名``,插入字符型用'';

 

 mysql_query("delete from `student4`where `name`='maning'");*/删除数据项

 /*$result=mysql_query("select * from `student4`;",$conn);//查询数据项

 while($rows=mysql_fetch_array($result))

 {

 echo $rows['id'].$rows['name'].$rows['sex'].$rows['age'];

 }*/

 mysql_query("update `student4` set `age`=12345 where `id`=1;");//修改数据项

?> 

<body>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: