1. SQL statements Used
MySQL -u root-p Enter password to connect to MySQL Database
SHOW DATABASES; View all databases in MySQL
Create DATABASES for creating a database
Drop database for deleting databases
Use database name Select database
SHOW tablses; To view all tables in a database
CREATE Table table name (field name type length constraint null); Create a Table statement
DESC table name view table structure
2. Example:
<?PHP//send a SQL statement that creates a data table to the MySQL database $link= @mysql_connect(' localhost ', ' root ', ' root '); //determine if the connection database is successful//Note add an exclamation mark, otherwise the connection database fails with the error number 0, cause 0 if(!$link){ die("Connection database failed with error number:".)Mysql_errno() . "Reason for failure".Mysql_errno()); } //Select Database $db=mysql_select_db("Test"); //determine if selecting a database is successful if(!$db){ die("Select database failed with error number:".)Mysql_errno() . "Reason for failure".Mysql_errno()); } //Assemble SQL statements that create tables $sql= "CREATE TABLE students ("; $sql. = "Stuid int (4) NOT NULL Auto_increment primary key,"; $sql. = "Stuname varchar () NOT NULL,"; $sql. = "Stusex tinyint not NULL default 1,"; $sql. = "Stubirth date not NULL,"; $sql. = "ClassId int (4) not null);"; //Execute CREATE TABLE statement if(mysql_query($sql)){ Echo"CREATE TABLE succeeded"; }Else{ Echo"Failed to create TABLE"; } //Close the database connection when the operation is complete Mysql_close($link);
PHP Note Six: Working with MySQL tables (creating tables)