The application of MySQL view to create a view
View is also called a virtual table, including a set of records returned by executing a query . Views can simplify the method of obtaining data and implement abstract queries through aliases.
In order to simplify the query, in the actual project development process, you can usually create a view for a certain table in the database. Only the fields that developers care about are created in the view. Enter the username and password of the logged-in user in the input box respectively. After clicking the "Enter" button, if the user enters an incorrect username or password, an error prompt will be given. Otherwise, if the entered username and password are correct, a successful login will be prompted. .
Recommended related mysql video tutorials: "mysql tutorial"
Technical points
Creating views in MySQL can be achieved through the create view statement. The specific creation format is as follows:
$create [ or deplace] [algorithm={merge | temptable | undefined}] view view_name[( column_list)] as select_statement [with [cascaded | local] check option]
algorithm={merge | temptable | undefined} attribute is used to optimize the execution of MySQL views. This attribute has 3 available set up. The following will introduce how to use these 3 settings.
merge: This parameter causes any clauses passed in when MySQL executes the view to be merged into the view's query definition.
temptable: If the data in the table below the view changes, these changes will be reflected immediately on the next pass through the table.
undefined: When the query result and the view result have a one-to-one correspondence, MySQL sets the algorithm to temptable.
view_name: The name of the new view.
select_statement: SQL query statement is used to limit the contents of the virtual table.
mysql view creation process
Since this example uses a view to create a virtual table, it should be created first under the "Command Prompt" view, you can create a view at the command prompt. The code to create the view is as follows:
create view chkadmin as select username, password from user
Create the view in the "Command Prompt" as follows:
After creating the view chkadmin, the view only contains There are two fields, username and password, which will bring great convenience to the password verification work.
Then we create the user input login interface, connect to the database, and determine whether the user clicked the "Enter" button. If so, verify the user identity through the view chkadmin. The process code is as follows:
<form method="post" action="3.php" name="form1"> 用户名:<input type="text" name="username" ><br> 密 码:<input type="password" name="pwd"><br> <input type="submit" name="Submit" value="进入"> <input type="submit" value="重置"> </form> <?php if($_POST['Submit']){ $name = $_POST['username']; $password = $_POST['pwd']; header("Content-Type:text/html; charset=utf-8"); $link = mysqli_connect("localhost", "root", "root"); $conn = mysqli_select_db($link, "php_cn"); $sql = ("select * from chkadmin where username='".$name."' and password = '".$password."'"); $result = mysqli_query($link, $sql); $res = mysqli_fetch_array($result, MYSQLI_ASSOC); if ($res==false){ echo "<script>alert('用户名或者密码输入错误');history.back();</script>"; exit(); }else{ echo "<br><p align='center'>登录成功!</p>"; } }
When we enter wrong information, as shown below:
When we enter correct information, as shown below:
Then we will introduce the MySQL creation view here. Have you guys mastered it? If you haven’t mastered it yet, you can read another article carefully. , in the next article we will continue to introduce the application of MySQL views. For details, please read "MySQL View Applications - Modifying Views"!
【Recommended related tutorials】
1.【MYSQL online free video tutorial】
2. Recommended related video courses : "Han Shunping's latest MySQL basic video tutorial in 2016"
The above is the detailed content of Application of MySQL view to create a view. For more information, please follow other related articles on the PHP Chinese website!

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
