- Mysql_query ("BEGIN ");
- Mysql_query ("insert into mermerinfo (name) VALUES ('$ name1 ')";
- Mysql_query ("SELECT * FROM 'orderinfo' where customerid =". $ id ");
- Mysql_query ("COMMIT ");
5) locking the table and optimizing transaction processing: a. We use a SELECT statement to retrieve the initial data and UPDATE the new value to the table through some calculations. The lock table statement containing the WRITE keyword ensures that no other access is allowed to insert, update, or delete the inventory before the unlock tables command is executed. Mysql_query ("lock table customerinfo READ, orderinfo WRITE"); mysql_query ("SELECT customerid FROM 'mermerinfo' where id = ". $ id); mysql_query ("UPDATE 'orderinfo' SET ordertitle = '$ title' where mermerid = ". $ id); mysql_query ("unlock tables ");6) use a foreign key to optimize the locking Table a. map the customerid in customerinfo to the customerid in orderinfo. any record without a valid customerid will not be written to orderinfo. Create table customerinfo (customerid int not null, primary key (customerid) TYPE = INNODB; create table orderinfo (orderid int not null, customerid int not null, primary key (customerid, orderid), foreign key (customerid) REFERENCES customerinfo (customerid) on delete cascade) TYPE = INNODB;Note: 'On delete cascade ', this parameter ensures that when a record in the customerinfo table is deleted, all records of the user in the order table are also deleted, note that the transaction security type should be defined as INNODB when the foreign key is used; 7) CREATE an INDEX: a. Format: (common INDEX)-> CREATE: CREATE INDEX <索引名> ON tablename (INDEX Field) modification: alter table tablename add index [INDEX name] (INDEX Field) create table specified INDEX: create table tablename ([...], INDEX [INDEX name] (INDEX Field) (unique index)-> CREATE: CREATE UNIQUE <索引名> ON tablename (index Field) modification: alter table tablename add unique [index name] (index Field) create table specified index: create table tablename ([...], UNIQUE [index name] (index Field) (primary key)-> It is a UNIQUE index. Generally, when creating a TABLE, it is created in the format of creata table tablename ([...], primary key [Index field]) 8) optimize the query statement a. It is best to compare the same fields and minimize the number of function operations on the created index fields. Example 1: SELECT * FROM order where year (orderDate) <2008; (slow) SELECT * FROM order WHERE orderDate <"2008-01-01"; (fast)Example 2: SELECT * FROM order WHERE addtime/7 <24; (slow) SELECT * FROM order WHERE addtime <24*7; (fast)Example 3: SELECT * FROM order WHERE title like "% good %"; SELECT * FROM order WHERE title> = "good" and name <"good ";6. what is the function for MYSQL to obtain the current time ?, The function for formatting a date is (2 points) answer: now (), dateformat () This php interview question focuses on the content of mysql Performance Optimization. it looks like a DBA for the mysql database programmed in php ~~ |