insert into student(xh,xm,xb)values
('170204',;男);
select*from student where xh='170204';
insert into student(xh,xm,xb)values
('170204',;男);
select*from student where xh='170204';
1.连接数据库服务器,选择数据库
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>连接数据库服务器,选择数据库</title>
</head>
<body>
<?php
$id=mysql_connect("localhost","root","root");
if($id){
echo "OK,选择数据库成功!;<br>";
$ok=mysql_select_db("student".$id);
if($ok){
echo "OK,选择数据库成功!";
}else{
echo "OH,选择数据库失败,请确认数据库是否存在。";
}else{
echo "OH,数据库连接失败!请检查服务器地址,用户名和地址是否正确!
<br>";
}
?></body>
</html>
2.用PHP创建新数据库和表
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用PHP</title>
</head>
<body>
<?php
if(!$id=mysql_connect("localhst","root","root")){
echo "数据库服务器连接错误!";
exit;
}
echo "数据库服务器连接成功!<br>";
if(!mysql_query("CREATE DATABASE newdata",$id)){
echo "数据库选择不成功"
exit;
}
echo "数据库选择成功!<br>";
if(!mysql_query("CREATE TABLE testtable(name varchar(10),age int(4))",$id)){
echo "数据表创建不成功,请检查SQL语句是否正确!";
exit;
}
echo "数据库创建成功!<br>";
if(mysql_close($id)){
echo "数据库服务器连接关闭成功!";
}
?>
</body>
</html>
3.用PHP向表中插入数据
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用PHP向表中插入数据</title>
</head>
<body>
<?php
$id =mysql_connect("localhost","root","root");
mysql_select_db("newdata",$id);
for($i=1;$i<6;$i++){
$nl=20+$i;
$xm="姓名".$i;
$sql="INSERT INTO testtble VALUES('".$xm.'","$nl.")";
$excu=mysql_query($sql,$id);
if($excu){
echo $sql;
echo "第".$i".条数据插入成功!<br>";
}
else{
echo "数据插入失败,错误信息:<br>";
echo mysql_error();
}
}
mysql_close($id);
?>
</body>
</html>
1.连接数据库服务器,选择数据库
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>连接数据库服务器,选择数据库</title>
</head>
<body>
<?php
$id=mysql_connect("localhost","root","root");
if($id){
echo "OK,选择数据库成功!;<br>";
$ok=mysql_select_db("student".$id);
if($ok){
echo "OK,选择数据库成功!";
}else{
echo "OH,选择数据库失败,请确认数据库是否存在。";
}else{
echo "OH,数据库连接失败!请检查服务器地址,用户名和地址是否正确!
<br>";
}
?></body>
</html>
2.用PHP创建新数据库和表
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用PHP</title>
</head>
<body>
<?php
if(!$id=mysql_connect("localhst","root","root")){
echo "数据库服务器连接错误!";
exit;
}
echo "数据库服务器连接成功!<br>";
if(!mysql_query("CREATE DATABASE newdata",$id)){
echo "数据库选择不成功"
exit;
}
echo "数据库选择成功!<br>";
if(!mysql_query("CREATE TABLE testtable(name varchar(10),age int(4))",$id)){
echo "数据表创建不成功,请检查SQL语句是否正确!";
exit;
}
echo "数据库创建成功!<br>";
if(mysql_close($id)){
echo "数据库服务器连接关闭成功!";
}
?>
</body>
</html>
3.用PHP向表中插入数据
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用PHP向表中插入数据</title>
</head>
<body>
<?php
$id =mysql_connect("localhost","root","root");
mysql_select_db("newdata",$id);
for($i=1;$i<6;$i++){
$nl=20+$i;
$xm="姓名".$i;
$sql="INSERT INTO testtble VALUES('".$xm.'","$nl.")";
$excu=mysql_query($sql,$id);
if($excu){
echo $sql;
echo "第".$i".条数据插入成功!<br>";
}
else{
echo "数据插入失败,错误信息:<br>";
echo mysql_error();
}
}
mysql_close($id);
?>
</body>
</html>
<!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>
<body>
<?php
$id=mysql_connect("localhost","root","root");
if(!$id){
echo"OK,数据库连接成功!<br>";
$ok=mysql_select_db("student",$id);
if($ok){
echo"OH,选择数据库失败,请确认数据库是否存在。";
}
}
else{
echo"OH,数据库连接失败!请检查服务器地址、用户名和地址是否正确!<br>";
}
?>
</body>
</html>
<!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>用PHP创建数据库和表</title>
</head>
<body>
<?php
if(!$id=mysql_connect("localhost","root","root")){
echo"数据库服务器连接错误!";
exit;
}
echo"数据库服务器连接成功!<br>";
if(!mysql_query("CREATE DATABASE newdata",$id)){
echo"数据库创建不成功,请检查账号权限和数据库是否已经存在!";
exit;
}
echo"数据库服务器创建成功!<br>";
if(!mysql_select_db("newdata",$id)){
echo"数据库选择不成功!";
exit;
}
echo"数据库选择成功!<br>";
if(!mysql_query("CREATE TABLE testtable(name varchar(10),age int(4))",$id)){
echo"数据表创建不成功,请检查SQL语句是否正确!<br>";
exit;
}
echo"数据表创建成功!<br>";
if(mysql_close($id)){
echo"数据库服务器连接关闭成功";
}
?>
</body>
</html>
<!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>用PHP向表中插入数据</title>
</head>
<body>
<?php
$id=mysql_connect("localhost","root","root");
mysql_select_db("newdata",$id);
for($i=1;$i<6;$i++){
$nl=20+$i;
$xm="姓名".$i;
$sql="INSERT INTO testtable VALUSE('".$xm."',".$nl.")";
$excu=mysql_query($sql,$id);
if($excu){
echo $sql;
echo "第".$i."条数据插入成功!<br>";
}
else
{
echo"数据插入失败,错误信息:<br>";
echo mysql_error();
}
}
mysql_close($id);
?>
</body>
</html>
<!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>用PHP从表中读取数据</title>
</head>
<body>
<?php
$id=mysql_connect("localhost","root","root");
mysql_select_db("newdata",$id);
$query="SELECT * FROM testtable";
$result=mysql_query($query,$id);
$datanum=mysql_num_rows($result);
echo"表testtable中共有".$datanum."条数据<br>";
?>
<table width="228" height="34" border="1">
<?php while($info=mysql_fetch_array($result,MYSQL_ASSOC)){ ?>
<tr>
<td width="99" height="28"><?php echo $info["name"]?></td>
<td width="113"><?php echo $info["age"]?></td>
</tr>
<?php }?>
</table>
<?php mysql_close($id);?>
</body>
</html>
1.连接数据库服务器,选择数据库
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>连接数据库服务器,选择数据库</title>
</head>
<body>
<?php
$id=mysql_connect("localhost","root","root");
if($id){
echo "OK,选择数据库成功!;<br>";
$ok=mysql_select_db("student".$id);
if($ok){
echo "OK,选择数据库成功!";
}else{
echo "OH,选择数据库失败,请确认数据库是否存在。";
}else{
echo "OH,数据库连接失败!请检查服务器地址,用户名和地址是否正确!
<br>";
}
?></body>
</html>
2.用PHP创建新数据库和表
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用PHP</title>
</head>
<body>
<?php
if(!$id=mysql_connect("localhst","root","root")){
echo "数据库服务器连接错误!";
exit;
}
echo "数据库服务器连接成功!<br>";
if(!mysql_query("CREATE DATABASE newdata",$id)){
echo "数据库选择不成功"
exit;
}
echo "数据库选择成功!<br>";
if(!mysql_query("CREATE TABLE testtable(name varchar(10),age int(4))",$id)){
echo "数据表创建不成功,请检查SQL语句是否正确!";
exit;
}
echo "数据库创建成功!<br>";
if(mysql_close($id)){
echo "数据库服务器连接关闭成功!";
}
?>
</body>
</html>
3.用PHP向表中插入数据
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用PHP向表中插入数据</title>
</head>
<body>
<?php
$id =mysql_connect("localhost","root","root");
mysql_select_db("newdata",$id);
for($i=1;$i<6;$i++){
$nl=20+$i;
$xm="姓名".$i;
$sql="INSERT INTO testtble VALUES('".$xm.'","$nl.")";
$excu=mysql_query($sql,$id);
if($excu){
echo $sql;
echo "第".$i".条数据插入成功!<br>";
}
else{
echo "数据插入失败,错误信息:<br>";
echo mysql_error();
}
}
mysql_close($id);
?>
1.连接数据库服务器,选择数据库
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>连接数据库服务器,选择数据库</title>
</head>
<body>
<?php
$id=mysql_connect("localhost","root","root");
if($id){
echo "OK,选择数据库成功!;<br>";
$ok=mysql_select_db("student".$id);
if($ok){
echo "OK,选择数据库成功!";
}else{
echo "OH,选择数据库失败,请确认数据库是否存在。";
}else{
echo "OH,数据库连接失败!请检查服务器地址,用户名和地址是否正确!
<br>";
}
?></body>
</html>
2.用PHP创建新数据库和表
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用PHP</title>
</head>
<body>
<?php
if(!$id=mysql_connect("localhst","root","root")){
echo "数据库服务器连接错误!";
exit;
}
echo "数据库服务器连接成功!<br>";
if(!mysql_query("CREATE DATABASE newdata",$id)){
echo "数据库选择不成功"
exit;
}
echo "数据库选择成功!<br>";
if(!mysql_query("CREATE TABLE testtable(name varchar(10),age int(4))",$id)){
echo "数据表创建不成功,请检查SQL语句是否正确!";
exit;
}
echo "数据库创建成功!<br>";
if(mysql_close($id)){
echo "数据库服务器连接关闭成功!";
}
?>
</body>
</html>
3.用PHP向表中插入数据
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用PHP向表中插入数据</title>
</head>
<body>
<?php
$id =mysql_connect("localhost","root","root");
mysql_select_db("newdata",$id);
for($i=1;$i<6;$i++){
$nl=20+$i;
$xm="姓名".$i;
$sql="INSERT INTO testtble VALUES('".$xm.'","$nl.")";
$excu=mysql_query($sql,$id);
if($excu){
echo $sql;
echo "第".$i".条数据插入成功!<br>";
}
else{
echo "数据插入失败,错误信息:<br>";
echo mysql_error();
}
}
mysql_close($id);
?>
</body>
</html>
<!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>
<body>
<?php
$id=mysql_connect("localhost","root","");
if($id){
echo "OK,数据库连接成功!";
}else{
echo "OH,选择数据可连接失败"
}
?>
</body>
</html>
------------------------------------
2
<!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>
<body>
<?php
$id=mysql_connect("localhost","root","");
if($id){
echo "OK,数据库连接成功!";
$ok=mysql_select_db("student",$id);
if($ok){
echo "OK,选择数据库成功!";
}else{
echo "OH,选择数据可连接失败,请确认数据库是否存在" ;
}
}else{
echo "OH,数据库连接失败!请检查服务器地址,用户名和密码是否正确!<br>";
}
?>
</body>
</html>
--------------------------
3
<!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>
<body>
<?php
if(!$id=mysql_connect("localhost","root","")){
echo "数据库服务器连接错误!";
exit;
}
echo "数据库服务器连接成功!<br>";
if(!mysql_query("CREATE DATABASE newdata",$id)){
echo "数据库创建不成功,请检查账号权限和数据库是否存在!";
exit;
}
echo "数据库创建成功!<br>";
if(!mysql_select_db("newdata",$id)){
echo "数据库选择不成功!";
exit;
}
echo "数据库选择成功!<br>";
if(!mysql_query("CREATE TABLE testtable(name varchar(10),age int(4))",$id)){
echo "数据表创建不成功,请检查SQL语句是否正确!";
exit;
}
echo "数据表创建成功<br>";
if(mysql_close($id)){
echo "数据库服务器关闭成功<br>";
}
?>
</body>
</html>
4
<!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>
<body>
<?php
$id=mysql_connect("localhost","root","");
mysql_select_db("newdata",$id);
for($i=1;$i<6;$i++){
$nl=20+$i;
$xm="姓名".$i;
$sql="INSERT INTO testtable VALUES('".$xm."',".$nl.")";
$excu= mysql_query($sql,$id);
if($excu){
echo $sql;
echo "第".$i."条数据插入成功!<br>";
}else{
echo "数据插入失败,错误信息:<br>";
echo mysql_error();
}
}
mysql_close($id);
?>
</body>
</html>
------------------
5
<!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>
<body>
<?php
$id=mysql_connect("localhost","root","");
mysql_select_db("newdata",$id);
$query="SELECT * FROM testtable";
$result=mysql_query($query,$id);
$datanum=mysql_num_rows($result);
echo "表testtable中共有".$datanum."条数据<br>";
?>
<table width="228" height="34" border="1">
<?php while($info=mysql_fetch_array($result,MYSQL_ASSOC)){?>
<tr>
<td width="99" height="28"><?php echo $info["name"]?></td>
<td width="113"> <?php echo $info["age"]?></td>
</tr>
<?php }?>
</table>
<?php mysql_close($id);?>
</body>
</html>
----------------
6
<!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>
<body>
<?php
$id=mysql_connect("localhost","root","");
mysql_select_db("newdata",$id);
$query="SELECT * FROM testtable";
$result=mysql_query($query,$id);
$datanum=mysql_num_rows($result);
$page_id=$_GET["page_id"];
if($page_id==""){
$page_id=1;
}
$page_size=2;
$page_num=cell($datanum/$page_size);
?>
表testtable中共有<?php echo $datanum?>条数据<br>
每页<?php echo $page_size;?>条,共<?php echo $page_num;?>页。<br>
<?php
for($i=1;$i<=$page_num;$i++){
echo "[<a href=?page_id=".$i.">".$i."</a>]";
}
$start=($page_id-1)*$page_size;
$query2="SELECT * FROM testtable limit $start,$page_size";
$result2=mysql_query($query2,$id);
?>
<table width="228" height="34" border="1">
<?php while($info=mysql_fetch_array($result2,MYSQL_ASSOC)){?>
<tr>
<td width="99" height="28"><?php echo $info["name"]?></td>
<td width="113"> <?php echo $info["age"]?></td>
</tr>
<?php }?>
</table>
<?php mysql_close($id);?>
</body>
</html>
1.连接数据库服务器,选择数据库
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>连接数据库服务器,选择数据库</title>
</head>
<body>
<?php
$id=mysql_connect("localhost","root","root");
if($id){
echo "OK,选择数据库成功!;<br>";
$ok=mysql_select_db("student".$id);
if($ok){
echo "OK,选择数据库成功!";
}else{
echo "OH,选择数据库失败,请确认数据库是否存在。";
}else{
echo "OH,数据库连接失败!请检查服务器地址,用户名和地址是否正确!
<br>";
}
?></body>
</html>
2.用PHP创建新数据库和表
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用PHP</title>
</head>
<body>
<?php
if(!$id=mysql_connect("localhst","root","root")){
echo "数据库服务器连接错误!";
exit;
}
echo "数据库服务器连接成功!<br>";
if(!mysql_query("CREATE DATABASE newdata",$id)){
echo "数据库选择不成功"
exit;
}
echo "数据库选择成功!<br>";
if(!mysql_query("CREATE TABLE testtable(name varchar(10),age int(4))",$id)){
echo "数据表创建不成功,请检查SQL语句是否正确!";
exit;
}
echo "数据库创建成功!<br>";
if(mysql_close($id)){
echo "数据库服务器连接关闭成功!";
}
?>
</body>
</html>
3.用PHP向表中插入数据
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用PHP向表中插入数据</title>
</head>
<body>
<?php
$id =mysql_connect("localhost","root","root");
mysql_select_db("newdata",$id);
for($i=1;$i<6;$i++){
$nl=20+$i;
$xm="姓名".$i;
$sql="INSERT INTO testtble VALUES('".$xm.'","$nl.")";
$excu=mysql_query($sql,$id);
if($excu){
echo $sql;
echo "第".$i".条数据插入成功!<br>";
}
else{
echo "数据插入失败,错误信息:<br>";
echo mysql_error();
}
}
mysql_close($id);
?>
</body>
</html>
<?php
$id=mysql_connect("localhost","root","");
if($id)
{
echo "服务器连接成功<br>";
mysql_query("CREATE DATABASE student",$id);
$db=mysql_select_db("student",$id);
if($db)
{
echo "数据库选择成功<br>";
}
else
{
echo "数据库选择失败<br>";
}
for($i=1;$i<6;$i++)
{
$name="姓名".$i;
$values=$i;
$sql="INSERT INTO testtable VALUES(".$name.",".$values.")";
$excu=mysql_query($sql,$id);
if($excu)
{
echo $sql."<br>";
echo "第".$i."条数据插入成功";
}
else
{
echo "插入失败,错误信息为:<br>";
echo mysql_error()."<br>";
}
}
}
else
echo"数据库连接失败<br>";
if(mysql_close($id))
{
echo "数据库关闭成功<br>";
}
else
echo "数据库关闭失败<br>";
?>
第一个
<!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>
<body>
<?php
$id=mysql_connect("localhost","root"."root");
if($id){
echo "OK,数据库连接成功!<br>";
$ok=mysql_select_db("student",$id);
if($ok){
echo "OK,选择数据库成功!";
}else{echo "OH,选择数据库失败,请确认数据库是否存在。";
}
}else{
echo "OH,数据库连接失败!请检查服务器地址、用户名是否正确!<br>";
}
?>
</body>
</html>
--------------------------------------
<!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>
<body>
<?php
if(!$id=mysql_connect("localhost","root","root")){
echo "数据库服务器连接错误!";
exit;
}
echo "数据库服务器连接成功!<br>";
if(!mysql_query("CREATE DATABASE newdata",$id)){
echo "数据库创建不成功,请检查账号权限和数据库是否已经存在!";
exit;
}
echo "数据库创建成功!<br>";
if(!mysql_select_db("newdata",$id)){
echo "数据库选择不成功!";
exit;
}
echo "数据库选择成功!<br>";
if(!mysql_query("CREATE TABLE testtable(name varchar(10),age int(4))",$id)){
echo "数据表创建不成功,请检查SQL语句是否正确!";
exit;
}
echo "数据表创建成功!<br>";
if(mysql_close($id)){
echo "数据服务器连接成功!";
}
?>
</body>
</html>
--------------------------------------<!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>
<body>
<?php
$id=mysql_connect("localhost","root","root");
mysql_select_db("newdata",$id);
for($i=1;$i<6;$i++){
$nl=20+$i;
$xm="姓名".$i;
$sql="INSERT INTO testtable VALUES('".$xm."',".$nl.")";
$excu=mysql_query($sql,$id);
if($excu){
echo $sql;
echo "第".$i."条数据插入成功!<br>";
}else{
echo "数据插入失败,信息错误:<br>";
echo mysql_error;
}
}
mysql_close($id);
?>
</body>
</html>
--------------------------------------<!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>
<body>
<?php
$id=mysql_connect("localhost","root","root");
mysql_select_db("newdata",$id);
$query="SELECT*FROM testtable";
$result=mysql_num_rows($result);
echo "表testtable中共有".$datanum."条数据<br>";
?>
<table width="228" height="34" border="1">
<?php while($info=mysql_fetch_array($result,MYSQL_ASSOC)){?>
<tr>
<td width="99" height="28"><?php echo $info["name"]?>
</td>
<td width="113"><?php echo $info["age"]?></td>
</tr>
<?php }?>
</table>
<?php mysql_close($id);?>
</body>
</body>
</body>
</html>
--------------------------------------<!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>
<body>
<?php
$id = mysql_connect("localhost","root","root");
if($id){
echo "OK,数据库连接成功!<br>";
$ok=mysql_select_db("student",$id);
if($ok)
{
echo "OK,选择数据库成功!";
}
else {
echo "OH,选择数据库失败,请确认数据库是否存在。";}
}else{
echo "OH,数据库连接失败!请检查服务器地址,用户名和地址是否正确
<br>";
}
?>
</body>
</html>
<!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>
<body>
<?php
if(!$id=mysql_connect("localhost","root","root")){
echo "数据库服务器连接错误!";
exit;}
echo "数据库服务器连接成功!<br>";
if(!mysql_query("CREAE DATABASE newdata",$id)){
echo "数据库创建不成功,请检查账号权限和数据库是否已经存在";
exit;
}
echo "数据库选择成功!<br>";
if(!mysql_query("CREAE DATABASE testtable(name varchar(10),age int(4))",$id))
{
echo "数据标配不成功";
exit;}
echo "数据表成功<br>";
if(mysql_close($id)){
}
?>
</body>
</html>
<?php
$id=mysql_connect("localhost","root","");
if($id)
{
echo "服务器连接成功<br>";
mysql_query("CREATE DATABASE student",$id);
$db=mysql_select_db("student",$id);
if($db)
{
echo "数据库选择成功<br>";
}
else
{
echo "数据库选择失败<br>";
}
if(!mysql_query("CREATE TABLE testtable(name varchar(10),age int(4))",$id))
{
echo "表创建失败!<br>";
exit;
}
else
echo"表创建成功<br>";
}
else
echo"数据库连接失败<br>";
if(mysql_close($id))
{
echo "数据库关闭成功<br>";
}
else
echo "数据库关闭失败<br>";
?>
<?php
$id=mysql_connect("localhost","root","root");
if($id){
echo "OK,数据库连接成功!<br>";
$ok=mysql_select_db("student",$id);
if($ok){
echo "OK,选择数据库成功!";
}else{
echo "OK,选择数据库失败,请确认数据库是否存在.";
}
}else{
echo "OH,数据库连接失败!请检查服务器地址、用户名和是否正确!<br>";
}
?>
----------------------------------------------
<?php
if (!$id=mysql_connect("localhost","root","root")){
echo "数据库服务器连接错误!";
exit; //如果数据库服务器连接不成功,退出程序执行
}
echo "数据库服务器连接成功!<br>";
if (!mysql_query("CREATE DATABASE newdata",$id)){
echo"数据库创建不成功,请检查账号权限和数据库是否已经存在!";
exit; //如果数据库创建不成功,退出程序执行
}
echo "数据库创建成功!<br>";
if (!mysql_select_db("newdata",$id)){
echo "数据库选择不成功!";
exit; //如果数据库选择不成功,退出程序执行
}
echo "数据库选择成功!<br>";
if (!mysql_query("CREATE TABLE testtable (name varchar(10), age int(4))",$id)){
echo "数据表创建不成功,请检查SQL语句是否正确!";
exit; //如果SQL执行不成功,退出程序执行
}
echo "数据表创建成功!<br>";
if (mysql_close($id)){
echo "数据服务器连接关闭成功!";
}
?>
----------------------------------------------
<?php
$id=mysql_connect("localhost","root","root");
mysql_select_db("newdata",$id);
for($i=1;$i<6;$i++){
$nl=20+$i;
$xm="姓名".$i;
$sql="INSERT INTO testtable VALUES('".$xm."',".$nl.")";
$excu=mysql_query($sql,$id);
if($excu){
echo $sql;
echo "第".$i."条数据插入成功!<br>";
}else{
echo "数据插入失败,错误信息:<br>";
echo mysql_error(); //输出上一次MySQL执行的错误信息
}
}
mysql_close($id);
?>
----------------------------------------------
<?php
$id=mysql_connect("localhost","root","root");
mysql_select_db("newdata",$id);
$query="SELECT * FROM testtable";
$result=mysql_query($query,$id);
$datanum=mysql_num_rows($result);
echo "表testtable中共有".$datanum."条数据<br>";
?>
<table width="228" height="34" border="1">
<?php while ($info=mysql_fetch_array($result,MYSQL_ASSOC)){ ?>
<tr>
<td width="99" height="28"><?php echo $info["name"]?> </td>
<td width="113"><?php echo $info["age"]?></td>
</tr>
<?php } ?>
</table>
<?php mysql_close($id);?>
----------------------------------------------
<?php
$id=mysql_connect("localhost","root","root");
mysql_select_db("newdata",$id);
$query="SELECT * FROM testtable";
$result=mysql_query($query,$id);
$datanum=mysql_num_rows($result);
$page_id=$_GET["page_id"];
if ($page_id==""){
$page_id=1;
}
$page_size=2; //定义每页显示条数
$page_num=ceil($datanum/$page_size);
?>
表testtable中共有<?php echo $datanum;?>条数据<br>
每页<?php echo $page_size;?>条,共<?php echo $page_num;?>页。<br>
<?php
for ($i=1;$i<=$page_num;$i++){
echo "[<a href=?page_id=".$i.">".$i."</a>]";
}
$start=($page_id-1)*$page_size;
$query2="SELECT * FROM testtable limit $start,$page_size";
$result2=mysql_query($query2,$id);
?>
<table width="228" height="34" border="1">
<?php while ($info = mysql_fetch_array($result2, MYSQL_ASSOC)) { ?>
<tr>
<td width="99" height="28"><?php echo $info["name"]?></td>
<td width="113"> <?php echo $info["age"]?></td>
</tr>
<?php }?>
</table>
<?php mysql_close($id);?>
insert into student(xh,xm,xb) values
('170204','Sunny','男');
select * from student shere xh=‘170204’;
insert into student(xh,xm,xb)values
('170204',;男);
select*from student where xh='170204';
insert into student(xh,xm,xb) values
('170204','男');
select *from student where xh ='170204';
insert into student(xh,xm,xb) valuse
('170204','Sunny',男);
select * from student where xh='170204';