The basic syntax for the CREATE TABLE statement in MySQL is:
The code is as follows |
Copy Code |
CREATE [temporary] TABLE [IF not EXISTS] tbl_name [(create_definition,...)] [Table_options] [Select_statement] |
Temporary: This keyword indicates that the newly created table with MySQL CREATE TABLE is a temporary table that will automatically disappear after the current session ends. Temporary tables are mainly used in stored procedures, and for MySQL, which does not currently support stored procedures, this keyword is generally not available.
IF not EXISTS: In fact, add a judgment before the table is being built to perform the CREATE TABLE operation only if the table does not currently exist. Use this option to avoid errors where the table already exists and cannot be created again.
Tbl_name: The table name of the table you want to create. The table name must conform to the rules for identifiers. The usual practice is to use only letters, numbers, and underscores in the table name. For example, titles, Our_sales, My_user1 and so on should be regarded as the table name of the comparison specification.
Create_definition: This is the key part of the MySQL CREATE TABLE statement. The properties of each column in the table are specifically defined in this section.
MySQL when getting Started with table statements
The code is as follows |
Copy Code |
CREATE TABLE Class Stu int Name varchar (20) Age int Area varchar (20) CREATE TABLE Score ( Stu Int, Name varchar (20), ke varchar (10), Fen int );
|
————
To resolve a character set encoding statement:
Declaring the character set:
The code is as follows |
Copy Code |
Set names GBK; $SETCHARACTERSETSQL = "Set names ' utf8′"; $ziti = mysql_query ($SETCHARACTERSETSQL, $conn); Var_dump ($ziti); echo ' <br/> ';
|
Finding a way seems to solve the problem.
In the installation of MySQL server, whether the choice of gb2312 or utf-8, there is no relationship, these character sets in the phpMyAdmin can be very good work, mainly their own script to correctly display Chinese, you can in the PHP script, after connecting the database, Execute the following statement before the formal data query is submitted:
The code is as follows |
Copy Code |
$SETCHARACTERSETSQL = "Set NAMES ' own use of character set '"; $Recordset 1 = mysql_query ($SETCHARACTERSETSQL, $conn _resource) or Die (Mysql_error ()); |
Then execute your own query statement, and the result is correct. Just tried gb2312 and utf-8, no problem.
Message This data is created:
code is as follows |
copy code |
create table MSG ( ID int primary key auto_increment, Title varchar (), name varchar (a), content varchar (1000) ); br>//Note Kanji Add "single quotes INSERT INTO msg (id,title,name,content) Values (1, ' come out of the intersection ', ' John ', ' It's raining so much today, can you be the boss? ’); INSERT INTO MSG (id,title,name,content) Values (2, ' I'm coming again ', ' Dick ', ' come late, second place '); INSERT INTO MSG (ID, title,name,content) Values (3, ' The third title ', ' Liu Bei ', ' male and female double Swords ', (4, ' fourth title ', ' Guan Yu ', ' Tsing Lung Yan Yue Dao '), (5, ' fifth title ', ' Zhang Fei ', ' Zhang Eight Serpent Spear '); INSERT INTO MSG (id,title,name,content) Values (6, ' sixth title ', ' Tang Junhao ', ' I am Handsome '); |
Emptying the table's data
The code is as follows |
Copy Code |
Truncate MSG
Add a semicolon after changing the note ID; Update msg Set Id=3 where name = ' Dick '; // Update msg Set id=2, Content = ' I'm still late, so it's second place. ' where name = ' Dick ';
|
Delete
The code is as follows |
Copy Code |
Delete from Msg where id = 2;
|
Inquire
The code is as follows |
Copy Code |
Select Name,content * from msg where ID > 2//There is no * asterisk PHP connection MySQL database server $conn = mysql_connect (' localhost ', ' root ', ' root '); $sql = ' Use Phptest '; mysql_query ($sql, $conn);
|
Read message