PHP programmer interview questions (classic summary, dominated by mysql)-php Tutorial

Source: Internet
Author: User
PHP programmer interview questions (classic summary, dominated by mysql)

  1. Mysql_query ("BEGIN ");
  2. Mysql_query ("insert into mermerinfo (name) VALUES ('$ name1 ')";
  3. Mysql_query ("SELECT * FROM 'orderinfo' where customerid =". $ id ");
  4. 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 ~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.