phpmyadmin教程

image.png

phpmyadmin教程javascript

image.png

管理頁進入phpmyadminphp

打開C:\wamp\apps\phpmyadmin3.5.1下的配置文件:config.inchtml

修改密碼
建立與修改數據庫、數據表java

image.png

image.png

image.png

字段類型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

image.png

image.png

平均分

image.png

image.png

排序

image.png

image.png

image.png

image.png

image.png

image.png

image.png

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> <option value='回族'>回族</option> </select></td> </tr> </table> <p align="center"> <input type="submit" name="Submit" value="Submit"> <input type="reset" name="Reset" value="Reset"> </p> </form> </body> </html>
<?php
//鏈接服務器
$conn = mysql_connect("localhost:3306","root",""); mysql_set_charset("gbk",$conn); mysql_select_db("dada"); //取數據 $studentId = $_REQUEST['studentId']; $name = $_REQUEST['name']; $className = $_REQUEST['className']; $birthday = $_REQUEST['birthday']; $sex = $_REQUEST['sex']; $nation = $_REQUEST['nation']; //寫語句 $sql= "INSERT INTO `student` VALUES (null,'$studentId','$name','$className','$birthday','$sex','$nation')"; //執行,返回值是true false $result = mysql_query($sql,$conn); if(!$result){ echo "插入失敗,語句寫錯了,請檢查!!"; }else{ echo "數據保存成功!!!<a href='insertStudent.php'>返回</a>"; }
<!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=gbk"> <script type="text/javascript" src="js/Calendar3.js"></script> <title>查詢</title> </head> <body> <?php session_start(); if(!isset($_SESSION["userName"])){ header("location:login.php"); } // 鏈接服務器 $conn = mysql_connect ( "localhost:3306", "root", "" ) or die ( "不能鏈接到服務器" . mysql_error () ); // 設定字符集 mysql_set_charset ( "gbk", $conn ); // 選擇數據庫 $sel = mysql_select_db ( "dada" ); if ($sel) { // 生成查詢語句 $sql = "SELECT * FROM `student` LIMIT 0, 30 "; // 查詢結果是一個二維(多行多列)的表狀結構 // 若是查詢結果爲空,注意不是查詢失敗,只不過$result是空記錄集 $result = mysql_query ( $sql, $conn ); echo "<center><b>查詢結果</b></center>"; echo "<hr>"; echo "<table width='100%' border=1 cellpadding=2 >"; echo "<tr><th>編號</th><th>學號</th><th>班級</th><th>生日</th><th>性別</th><th>民族</th><th>操做</th></tr>"; // 取出一行,MYSQL_ASSOC是一個常量,注意不加雙引號,表示返回結果是關聯數組 if ($result) { echo "<tr>"; // mysql_fetch_array,取出一行後,指針會自動指向下一行 while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) { // 關聯數組的鍵名是表中的字段名 echo "<td>" . $row ["id"] . "</td><td>" . $row ["studentId"] . "</td><td>" . $row ["name"] . "</td><td>" . $row ["className"] . "</td><td>" . $row ["sex"] . "</td><td>" . $row ["nation"] . "</td><td><a href=deleteStudent.php?id=".$row ["id"].">刪除</a></td></tr>"; // echo $row ["id"] . " " . $row ["name"]."<br/>"; } echo "</table>"; } else { echo "查詢失敗"; } } else { echo "數據庫不存在!!!"; } ?>
<?php //鏈接服務器 $conn = mysql_connect("localhost:3306","root",""); mysql_set_charset("gbk",$conn); mysql_select_db("dada"); //取數據 $id = $_REQUEST['id']; //寫語句 $sql= "delete from student where id='$id'"; echo $sql; //執行,返回值是true false $result = mysql_query($sql,$conn); if(!$result){ echo "刪除失敗,語句寫錯了,請檢查!!"; }else{ header("location:index.php"); } ?>
相關文章
相關標籤/搜索