Mysql basic statement bitsCN.com
Reprinted from:
Jingw.15303.bolg.163.com
Show databases; displays the database
Create database DataBaseName; create a database
Drop databases database name delete database
Drop table name delete table
Use databaseName; enter the corresponding database
Show tables; view tables in the current database
Some data types in MySQL (dateType ):
Integer
Varchar (Number) Number can be any integer
Text type, can store a large number of text
Float
Date type
Create a table
Create table tableName (
ColumnName dataType,
.................
ColumnName dataType
Primary key ('id'); set ID to primary key
Not null auto_increment. you can use the AUTO_INCREMENT attribute to generate a unique identifier for the new row:
Example: create table xxx (
Id integer not null AUTO_INCREMENT,
Name CHAR (30) not null,
Primary key (id)
);
Add: insert into tableName values (value, value, value ......); Insert information to tableName
Query: select * from tableName; view all data in the current table
Delete from tableName where condition; delete data in the database
Modify the update tableName set condition. modify the data in the database.
Basic steps for mysql:
(1) mysql_connect ("localhost", "root", "Password") | die ("failed to connect to database server ");
(2) mysql_select_db ("database name") | die ("connect to database ");
(3) $ strsql = "(Edit in Phpmyadmin)"; send an SQL statement
(4) mysql_query ("set names 'gb2312'"); prevents garbled characters
(5) $ res = mysql_query ($ strsql) receives SQL statements
(6) Mysql_colse (); end
$ A = Mysql_fetch_row ();
Description
The next row of the result set. When used after mysql_store_result (), if no row is to be retrieved, mysql_fetch_row () returns NULL. Mysql_use_result () returns NULL if no row to be retrieved or an error occurs.
The number of intra-row values is given by mysql_num_fields (result. If the value returned by calling mysql_fetch_row () is saved in the row, the pointer to these values is accessed according to row [0] to row [mysql_num_fields (result)-1. The NULL value in the row is specified by the NULL pointer.
You can call mysql_fetch_lengths () to obtain the length of the field value in the row. For NULL fields and NULL fields, the length is 0. By checking the pointer of field values, you can differentiate them. If the pointer is NULL and the field is NULL, otherwise the field is NULL.
Return value
The MYSQL_ROW structure of the next row. If there are no more rows to be retrieved or an error occurs, NULL is returned.
$ B = mysql_num_rows ();
Description
The number of rows in the returned result set.
The use of mysql_num_rows () depends on whether mysql_store_result () or mysql_use_result () is used to return the result set. If mysql_store_result () is used, you can call mysql_num_rows () immediately (). If mysql_use_result () and mysql_num_rows () are used, the correct value is not returned until all rows in the result set are retrieved.
Return value
Number of rows in the result set
BitsCN.com