mSQL Database Management

Source: Internet
Author: User
Tags logical operators rounding plus

Manual management, file system, database system three stages. DBMS database management system, relational database management system Rsbms. MySQL is the database management system. Data Model: Entity-Contact. E-r model. An entity rectangle, an attribute ellipse, attached with a non-tangential edge. Contact: Diamond, can even attribute. One to one, one to many, many to many. SQL (Structured Query Language) Structured Query language. IMB development. SQL type: Data definition language SSL, Data manipulation language DML, Data Control Language DCL. MySQL database management tool is a command line or a third-party graphical interface, such as Phpmyadmin.mysql has functions. system databases such as MYSL and information_schema are not allowed to be deleted. Delete the database name from the drop databases and confirm that the database exists before recovering the database. The data type of the column to be specified. Fixed-point number type decimal, single-precision float, double-precision doubles. Date type, datetime date and Time type, time type. int does not need to be set length. Modify the table structure of the command before ALTER TABLE. The self-increment property value can be filled out. MySQL has relational operators and logical operators. Anti-quotes can replace single quotes. Distinct filters duplicate data from the table name (one or more). Order By default Ascending. MySQL does not support double quotes. Count (), Avg,sum,min,max can query the information for the specified column. Where cannot contain aggregate functions, preceded by aggregate functions, with having. Connection query: Chado table, where sets the join condition. Each table has an alias. INNER join inside joins, condition on. A subquery refers to a select nested Select,where and having a select that can be nested. A view is a virtual table and a query that is saved in a database. CREATE VIEW name as SELECT statement. Die () and exit () are PHP exit Mysql.multi_query () Execute multiple SQL statements. Show records on page n select * from table name limit start position, display the number of record bars, such as SELECT * from table name limit ($page-1) * $pagesize, $pagesize; now is the first page, cancel home and previous page connection, last Acting Gets the total number of records for the result set select COUNT (1) from table name; current page: $page. " /". $pagecount

-------------------------------------------------------------------------------------------------

<HTML>
<HEAD><TITLE> pagination Display Records </TITLE>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
</HEAD>
<BODY>
<? Php
Get current page number
$page = $_get[' page '];
if ($page = = 0)
$page = 1;

$PageSize = 3;//In order to demonstrate the paging effect,
Connecting to a database
$conn = Mysqli_connect ("localhost", "root", "pass", "MySQLdb");
if (empty ($conn)) {
Die ("Mysqli_connect failed:". Mysqli_connect_error ());
}
Set Chinese Character set
Mysqli_query ($conn, "SET NAMES gb2312");
Execute SELECT statement to get the total number of records for table employees
$sql = "Select COUNT (1) from Employees";
$results = $conn->query ($sql);
$row = $results->fetch_row ();
$RecordCount = $row [0];
//////////////
Calculate Total Pages//
/////////////
if ($RecordCount) {
If the total number of records is less than the number of records displayed per page, only one page
if ($RecordCount < $PageSize) {
$PageCount = 1;
}
The total number of records cannot be divided evenly by the amount of records displayed per page, and the number of pages equals the total record count by the result of the number of records displayed per page rounding plus 1
if ($RecordCount% $PageSize) {
$PageCount = (int) ($RecordCount/$PageSize) + 1;
}
else {//if there is no remainder, the number of pages equals the total record count divided by the number of records displayed per page
$PageCount = $RecordCount/$PageSize;
}
}
else{//If there are no records in the result set, the number of pages is 0
$PageCount = 0;
}
Echo ("<BR> current page:".) $page. "/" . $PageCount);

?>
<table width= "449" border= "1" >
<tr>
<td> Employee Name </td>
<td> position </td>
<td> Wages </td>
</tr>
<? Php
Cycle through the records of the current page
$sql = "Select EmpName, Title, Salary from Employees LIMIT". ($page-1) * $PageSize. "," . $PageSize;
$results = $conn->query ($sql);
while ($row = $results->fetch_row ()) {
Echo ("<tr>");
Echo ("<td>". $row [0]. "&nbsp;</td>");
Echo ("<td>". $row [1]. "&nbsp;</td>");
Echo ("<td>". $row [2]. "&nbsp;</td>");
Echo ("</tr>");
}
Close connection
Mysqli_close ($conn);
Show Page-Paging links
if ($page = = 1)
Echo ("first page");
Else
Echo ("<a href=viewpage.php?page=1> first page </a>");
Set up a previous page link
if ($page = = 1)
Echo ("prev");
Else
Echo ("<a href=viewpage.php?page=". ($page-1). "> Prev </a>");
Set the next page link
if ($page = = $PageCount)
Echo ("next page");
Else
Echo ("<a href=viewpage.php?page=". ($page + 1). "> Next </a>");
Set the last page link
if ($page = = $PageCount)
Echo ("last page");
Else
Echo ("<a href=viewpage.php?page=". $PageCount. "> Last page </a>")
?>
</table>
</BODY>
</HTML>

mSQL Database Management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.