phpmyadmin教程javascript
管理页进入phpmyadminphp
打开C:\wamp\apps\phpmyadmin3.5.1下的配置文件:config.inchtml
修改密码
建立与修改数据库、数据表java
字段类型mysql
Int 整形
Date 时间
Varchar可变长度的字符串,要指定最大位数
Char 固定长度的字符串,指定固定位数
Double
Floatsql
索引shell
Primary,主键
Unique,惟一
Index,索引
统计函数数据库
AVG(字段名) 得出一个表格栏平均值
COUNT(*;字段名) 对数据行数的统计或对某一栏有值的数据行数统计
MAX(字段名) 取得一个表格栏最大的值
MIN(字段名) 取得一个表格栏最小的值
SUM(字段名) 把数据栏的值相加数组
查询去除重复值:select distinct * from table1bash
建立数据库
Create DATABASE databasename
删除数据库
drop database databasename
删除新表
drop table tabname
增长一个列
Alter table tabname add colname coltype
删除一个列
Alter table tabname drop column colname
添加主键
Alter table tabname add primary key(col)
建立索引
create [unique] index idxname on tabname(col…。)
建立视图
create view viewname as select statement
指定id,数据传入一个null
平均分
排序
mysql教程
链接到一个 MySQL 数据库
mysql_connect() 函数完成
mysql_connect(servername,username,password);
链接数据库
<?php $con = mysql_connect("localhost",“root",“12345"); if (!$con) { die('Could not connect: ' . mysql_error()); } // some code ?>
关闭链接
<?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } // some code mysql_close($con); ?>
建立数据库和建立表
CREATE DATABASE database_name
CREATE TABLE table_name ( column_name1 data_type, column_name2 data_type, column_name3 data_type, ....... )
SELECT 语句查询数据
SELECT column_name(s) FROM table_name
<?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(“my_db”, $con); //选择数据库 $result = mysql_query("SELECT * FROM person"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; } mysql_close($con); ?>
mysql_fetch_array
while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; }
mysql_fetch_array() 函数以数组的形式从记录集返回第一行
while loop 语句会循环记录集中的全部记录
链接:
$con = mysql_connect("localhost:3306","root","");
字符集:
mysql_set_charset("gbk",$con);
数据库:
mysql_select_db("ddd",$con);
查询:
$query = "select * from student"; $result = mysql_query($query);
取得结果集:
while($row =mysql_fetch_array($result))
ORDER BY
SELECT column_name(s) FROM table_name ORDER BY column_name
<?php $con = mysql_connect(“localhost”,“peter”,“abc123”); //链接数据库 if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(“my_db”, $con); //选择要操做的数据库名 mysql_query("INSERT INTO person (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')"); mysql_query("INSERT INTO person (FirstName, LastName, Age) VALUES ('Glenn', 'Quagmire', '33')"); mysql_close($con); ?>
<html> <body> <form action="insert.php" method="post"> Firstname: <input type="text" name="firstname" /> Lastname: <input type="text" name="lastname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html>
<?php $conn = mysql_connect ( "localhost:3306", "root", "" ); if (! $conn) { echo "不能链接到MYSQL数据库!"; } else { // 选择数据库 $select = mysql_select_db ( "dada", $conn ); if ($select) { // 查询语句 $sql = "select * from student"; //查询命令 $result = mysql_query($sql,$conn); $row = mysql_fetch_array($result); var_dump($row); } else { echo "dada" . "不存在!"; } } mysql_close ( $conn ); ?>
<?php //链接服务器 $conn = mysql_connect("localhost:3306",'root','') or die("不能链接服务器".mysql_error()); //设置来自数据库的数据的字符集 //特别注意:mysql_set_charset("utf8",$conn); mysql_set_charset("gbk",$conn); //选择数据库 $selectDb = mysql_select_db("dada",$conn); if(!$selectDb){ echo "数据库不存在!"; } ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <?php header('Content-type: text/html; charset=gbk'); require_once 'dbconfig.php'; //写查询语句 $sql = "SELECT * FROM `student` WHERE 1 LIMIT 0, 30 "; //执行查询,获得记录集,是一个二维表状结构,有行有列 $result = mysql_query($sql,$conn); //请注意,查询失败与查询到一个空记录集是两回事 if(!$result){ die("查询失败!"); } //取出结果集中的一行 $row = mysql_fetch_array($result); if($row){ //var_dump($row); foreach ($row as $key=>$value){ echo $key.":".$value."<br/>"; } } ?> </body> </html>
<?php // 链接到服务器,返回值resource或者false $conn = mysql_connect ( "localhost:3306", "root", "" ); if (! $conn) { echo "不能链接到MYSQL数据库!" . mysql_error (); } else { // 设置数据库的字符集 // 特别注意设置utf-8字符集: mysql_set_charset('utf8',$conn); mysql_set_charset ( 'gbk', $conn ); // 选择数据库,返回值true或者false $select = mysql_select_db ( "dada", $conn ); if ($select) { // 撰写查询语句 $sql = "select * from student"; // 执行查询命令,获得记录集 // 记录集是是一个多行多列的表格状多 // 注意:查询无内容,获得一个空记录集,但查询成功 $result = mysql_query ( $sql, $conn ); if (! $result) { echo "查询失败!!"; } else { // 若是取出内容不为空,一行数据 // $row = mysql_fetch_array ( $result ); // if ($row!=null) { echo "<center>查询结果</center>"; echo "<hr/>"; echo "<table border=1 width=800 align='center'>"; echo "<tr>"; echo "<th>记录号</th><th>学号</th><th>姓名</th><th>班级></th><th>生日</th><th>性别</th><th>民族</th>"; echo "</tr>"; while ( $row = mysql_fetch_array ( $result ) ) { // 访问关联数组,键名是数据库表的字段名 echo "<tr align='center'>"; echo "<td>".$row ['id']."</td>"; echo "<td>".$row ['studentId']."</td>"; echo "<td>".$row ['name']."</td><td>".$row ['className']."</td><td>".$row ['birthday']."</td><td>".$row ['sex']."</td><td>".$row ['nation']."</td>"; echo "</tr>"; } } } else { echo "gdmec" . "不存在!"; } } mysql_close ( $conn ); ?>
显示日历
<script type="text/javascript" src="js/Calendar3.js"></script> onclick="new Calendar().show(this);"
<html> <head> <title>Login</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <script type="text/javascript" src="js/Calendar3.js"></script> </head> <body> <center> <b>增长学生信息</b> </center> <hr> <form name="form1" method="post" action="insertStudentdo.php"> <table width="300" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td width="150"><div align="right">学号:</div></td> <td width="150"><input type="text" name="studentId" maxlength='8'></td> </tr> <tr> <td><div align="right">姓名:</div></td> <td><input type="text" name="name"></td> </tr> <tr> <td width="150"><div align="right">班级:</div></td> <td width="150"><input type="text" name="className"></td> </tr> <tr> <td width="150"><div align="right">生日:</div></td> <td width="150"><input type="text" id="birthday" name="birthday" onclick="new Calendar().show(this);"></td> </tr> <tr> <td width="150"><div align="right">性别:</div></td> <td width="150"><input type="radio" name="sex" value='男'>男</input> <input type="radio" name="sex" value='女' checked>女</input></td> </tr> <tr> <td width="150"><div align="right">民族:</div></td> <td width="150"><select name="nation"> <option value='汉族'>汉族</option> <option value='白族'>白族</option>