Home > headlines > PHP interview questions and answers updated on June 3, 2018

PHP interview questions and answers updated on June 3, 2018

PHP中文网
Release: 2018-06-04 20:20:20
Original
6962 people have browsed it

php interview questions and answers updated on June 3, 2018 include PHP basic part, database part, object-oriented part, ThinkPHP part, smarty template engine, secondary development system (DEDE, ecshop), WeChat public platform development, Several PHP interview questions including description of the technology you have mastered.

1. One of the major advantages of PHP language is cross-platform. What is cross-platform?

The optimal running environment of PHP is Apache MySQL PHP. This running environment can be configured on different operating systems (such as windows, Linux, etc.) and is not restricted by the operating system, so it is called cross-platform

2. How many methods are there for data submission in WEB development? What's the difference? Which method does Baidu use?

Get and post two methods
Difference:
1. Get obtains data from the server, and post transmits data to the server
2. The value passed by Get is visible in the url, and post is in the url Invisible
3. The value passed by Get is generally within 2KB, and the size of the value passed by post can be set in php.ini
4. Get is not low in security, post is more secure, and its execution efficiency is higher than Post
Recommendations:
1. The get type is less secure than the Post type. It is recommended to use the Post data submission type if it contains confidential information;
2. It is recommended to use the Get type for data query; to add, modify or delete data. It is recommended to use the Post method;
The get method used by Baidu, because it can be seen from its URL

PHP interview question bank network disk download

PHP interview question bank Netdisk download

Question bank download: PHP interview questions summary Netdisk download

3. Master which frameworks, template engines, systems, etc. of PHP

Framework: The framework has There are many, such as zendframe, CI, Yii, etc. What we have learned is thinkphp
template engine: there are also many, which are in the textbooks. What we have learned is smarty
system: there are many, such as: Kangsheng's Products (uchome, supesite, discuzX, etc.), Empire System, DEDE (Dreamweaver), ecshop, etc. What we have learned is DEDECMS, Ecshop

4. What are the web front-end technologies you have mastered?

Proficient in DIV CSS web page layout, JavaScript, jQuery framework, photoshop image processing

5. What are the advantages of AJAX?

ajax is an asynchronous transmission technology that can be implemented through javascript or through the JQuery framework to achieve partial refresh, which reduces the pressure on the server and improves the user experience

6. Security to one It is very important for a set of programs. Please tell me what safety mechanisms should be paid attention to during development?

① Prevent remote submission; ② Prevent SQL injection and filter special codes; ③ Prevent registration machine flooding and use verification codes;

7. In the development of the program, how to improve the performance of the program operating efficiency?

① Optimize SQL statements, try not to use select * in query statements, use which field to check which field; use less subqueries instead of table connections; use less fuzzy queries; ② Create indexes in data tables; ③ Right The data frequently used in the program is cached;

8. Can PHP be used with other databases?

PHP and MYSQL database are the best combination. Of course, PHP can also be used with other databases, such as MSSQL, etc. PHP has reserved functions for operating MSSQL, which can be used as long as it is turned on


9. Nowadays, the MVC three-layer structure is often used in programming. What are the three layers of MVC? What are the advantages?

The three layers of MVC refer to: business model, view, and controller. The controller layer calls the model to process the data, and then maps the data to the view layer for display. The advantages are: ① It can achieve code reusability, Avoid code redundancy; ②M and V implement code separation, so that the same program can use different expressions

10. Understanding of json data format?

JSON (JavaScript Object Notation) is a lightweight data exchange format. The json data format is fixed and can be used for data transfer in multiple languages.
The function in PHP that processes json format is json_decode (string $json [, bool $assoc]), accepts a JSON format string and converts it into a PHP variable. The parameter json is the json string format string to be decoded. assoc When this parameter is TRUE, it will return array instead of object;
Json_encode: Convert PHP variables into json format

11. What is the difference between Print, echo, and print_r?

① Both echo and print can do output. The difference is that echo is not a function and has no return value, while print is a function with a return value, so relatively speaking it will be faster if it only outputs echo, and print_r Usually used to print information about variables, often used in debugging.
② print is to print a string
③ print_r is to print a composite type such as an array object

12. What is the difference between SESSION and COOKIE?

①Storage location: session is stored on the server, cookie is stored in the browser
②Security: session security is higher than cookie
③session is a 'session service', and the service needs to be turned on when using it. Cookies do not need to be turned on. You can directly use

13. What are the common functions for processing arrays in PHP? (Focus on the 'parameters' and 'return value' of the function)

①array() creates an array; ②count() returns the number of elements in the array; ③array_push() inserts one or more elements into the end of the array ( Pushing onto the stack); ④array_column() returns the value of a single column in the input array; ⑤array_combine() creates a new array by merging two arrays; ⑥array_reverse() returns the array in reverse order; ⑦array_unique() removes duplicates in the array Value; ⑧in_array() checks whether the specified value exists in the array;

14. Common functions for processing strings in PHP? (Focus on the 'parameters' and 'return value' of the function)

①trim() removes blank characters and other characters on both sides of the string;
②substr_replace() replaces part of the string with another A string;
③substr_count() counts the number of times a substring appears in the string;
④substr() returns a part of the string;
⑤strtolower() converts the string to lowercase letters;
⑥strtoupper() converts the string to uppercase letters;
⑦strtr() converts specific characters in the string;
⑧strrchr() finds the last occurrence of the string in another string;
⑨strstr() Find the first occurrence of a string in another string (case sensitive); strrev() reverses the string; strlen() returns the length of the string; str_replace() replaces some characters in the string (for Case sensitive); print() outputs one or more strings; explode() breaks the string into an array; is_string() detects whether the variable is a string; strip_tags() removes HTML tags from a string; mb_substr ()Function used to intercept Chinese and English characters

15. Commonly used functions for PHP processing time? (Focus on the ‘parameters’ and ‘return value’ of the function)

date_default_timezone_get() returns the default time zone.
date_default_timezone_set() sets the default time zone.
date() formats local time/date.
getdate() returns date/time information.
gettimeofday() returns the current time information.
microtime() returns the number of microseconds in the current time.
mktime() returns the Unix timestamp of a date.
strtotime() parses any English text date or time description into a Unix timestamp.
time() returns the Unix timestamp of the current time.

16. Common functions used by PHP to process databases? (Focus on the 'parameters' and 'return value' of the function)

Please refer to the PHP manual and read it carefully. This item is very important.

17. What are the commonly used functions for operating files in PHP? (Focus on the 'parameters' and 'return value' of the function)

①Open the file; ②Delete the file; ③Read the file; ④Write the file; ⑤Modify the file; ⑥Close the file; ⑦Create file, etc. etc. This item is very important. It is often used to generate cache or static files at work. Please refer to the PHP manual and carefully check

18. What are the common functions of PHP operating directories (folders)? (Focus on the 'parameters' and 'return value' of the function)

①Open the directory; ②Delete the directory; ③Read the directory; ④Create the directory; ⑤Modify the directory; ⑥Close the directory, etc. This item is very Important, at work, you often use to create or delete directories for uploaded files, create or delete directories for caches and static pages, please refer to the PHP manual and read carefully

II: Database part

Return Top

1. What are the common relational database management system products?

Answer: Oracle, SQL Server, MySQL, Sybase, DB2, Access, etc.

2. What parts does SQL language include? What are the action keywords for each section?

Answer: SQL language includes four parts: data definition (DDL), data manipulation (DML), data control (DCL) and data query (DQL).
Data definition: Create Table, Alter Table, Drop Table, Craete/Drop Index, etc.
Data manipulation: Select, insert, update, delete,
Data control: grant, revoke
Data query: select

3. What do integrity constraints include?

Answer: Data Integrity refers to the accuracy and reliability of data.
It is divided into the following four categories:
1) Entity integrity: It stipulates that each row of the table is a unique entity in the table.
2) Domain integrity: means that the columns in the table must meet certain data type constraints, which include value range, precision and other regulations.
3) Referential integrity: means that the data of the primary key and foreign key of the two tables should be consistent, ensuring the consistency of data between tables and preventing data loss or meaningless data in the database. diffusion.
4) User-defined integrity: Different relational database systems often require some special constraints depending on their application environments. User-defined integrity is a constraint for a specific relational database, which reflects the semantic requirements that a specific application must meet.
Table-related constraints: including column constraints (NOT NULL (non-null constraints)) and table constraints (PRIMARY KEY, foreign key, check, UNIQUE).

4. What is a transaction? and its characteristics?

Answer: Transaction: It is a series of database operations and the basic logical unit of database application.
Transaction characteristics:
(1) Atomicity: that is, indivisibility. Either all transactions are executed or none are executed.
(2) Consistency or stringability. The execution of a transaction converts the database from one correct state to another correct state
(3) Isolation. Before the transaction is correctly committed, any changes to the data by the transaction are not allowed to be provided to any other transaction,
(4) Durability. After a transaction is submitted correctly, its results will be permanently saved in the database. Even if there are other failures after the transaction is submitted, the processing results of the transaction will be saved.
Or understand it this way:
A transaction is a group of SQL statements that are bound together as a logical unit of work. If any statement operation fails, the entire operation will fail, and future operations will be rolled back to the state before the operation. , or there is a node on it. To ensure that something is either executed or not executed, transactions can be used. For a grouped statement to be considered a transaction, it needs to pass the ACID tests, namely atomicity, consistency, isolation, and durability.

5. What is a lock?

Answer: The database is a shared resource used by multiple users. When multiple users access data concurrently, multiple transactions simultaneously access the same data in the database. If concurrent operations are not controlled, incorrect data may be read and stored, destroying the consistency of the database.
Locking is a very important technology to achieve database concurrency control. Before a transaction operates on a data object, it first sends a request to the system to lock it. After locking, the transaction has certain control over the data object. Before the transaction releases the lock, other transactions cannot update the data object.
Basic lock types: Locks include row-level locks and table-level locks

6. What is a view? What is a cursor?

Answer: A view is a virtual table that has the same functions as a physical table. Views can be added, modified, checked, and operated. A view is usually a subset of rows or columns of one table or multiple tables. Modifications to the view do not affect the underlying tables. It makes it easier for us to obtain data compared to multi-table queries.
Cursor: It effectively processes the query result set as a unit. The cursor can be positioned on a specific row in the cell to retrieve one or more rows from the current row in the result set. You can make changes to the current row of the result set. Cursors are generally not used, but when data needs to be processed one by one, cursors are very important.

7. What is a stored procedure? What to call?

Answer: The stored procedure is a precompiled SQL statement. The advantage is that it allows a modular design, which means that it only needs to be created once and can be called multiple times in the program later. If a certain operation requires multiple executions of SQL, using stored procedures is faster than executing simple SQL statements. Stored procedures can be called using a command object.

8. What is the role of index? And what are its advantages and disadvantages?

Answer: An index is a special query table that the database search engine can use to speed up data retrieval. It is very similar to the table of contents of a book in real life. You can find the data you want without querying the entire book. Indexes can be unique. Creating an index allows you to specify a single column or multiple columns. The disadvantage is that it slows down data entry and increases the size of the database.

9. How to understand the three paradigms in a popular way?

Answer: First normal form: 1NF is an atomicity constraint on attributes, which requires attributes to be atomic and cannot be decomposed;
Second normal form: 2NF is a uniqueness constraint on records, which requires records to have Unique identification, that is, the uniqueness of the entity; Third normal form: 3NF is a constraint on field redundancy, that is, any field cannot be derived from other fields, and it requires that the fields are not redundant. .

10. What is a basic table? What is a view?

Answer: The basic table is a table that exists independently. In SQL, a relationship corresponds to a table. A view is a table derived from one or several base tables. The view itself is not stored independently in the database, but is a virtual table

11. Describe the advantages of views?

Answer: (1) Views can simplify user operations (2) Views enable users to view the same data from multiple perspectives; (3) Views provide a certain degree of logical independence for the database; (4) Views provide security protection for confidential data.

12. What does NULL mean?

Answer: The value NULL represents UNKNOWN (unknown): it does not represent "" (empty string). Any comparison against a NULL value will produce a NULL value. You cannot compare any value to a NULL value and logically expect to get an answer.
Use IS NULL for NULL judgment

13. What is the difference between primary key, foreign key and index?

The difference between primary key, foreign key and index
Definition:
Primary key--uniquely identifies a record, cannot be duplicated, and is not allowed to be empty
Foreign key--the foreign key of the table is another The primary key and foreign key of the table can have duplicates or null values ​​
Index--the field has no duplicate values, but can have a null value
Function:
Primary key--used to ensure data integrity
Foreign key - used to establish connections with other tables
Index - to improve the speed of query sorting
Number:
Primary key - the primary key can only have one
foreign key --A table can have multiple foreign keys
Indexes--A table can have multiple unique indexes

14. What can you use to ensure that the fields in the table only accept values ​​in a specific range?

Answer: Check restriction, which is defined in the database table, is used to limit the value entered in this column.
Triggers can also be used to limit the values ​​that fields in database tables can accept, but this method requires triggers to be defined in the table, which may affect performance in some cases.

15. What are the methods to optimize SQL statements? (Select a few)

(1) In the Where clause: The connection between the where tables must be written before other Where conditions, and those conditions that can filter out the maximum number of records must be written at the end of the Where clause .HAVING last.
(2) Use EXISTS to replace IN, and use NOT EXISTS to replace NOT IN.
(3) Avoid using calculations on index columns
(4) Avoid using IS NULL and IS NOT NULL on index columns
(5) To optimize queries, full table scans should be avoided as much as possible. First of all Consideration should be given to creating indexes on the columns involved in where and order by.
(6) Try to avoid making null value judgments on fields in the where clause, otherwise the engine will give up using the index and perform a full table scan
(7) Try to avoid making null value judgments on fields in the where clause. Expression operation, which will cause the engine to give up using the index and perform a full table scan

16. What is the difference between 'correlated subquery' and 'non-correlated subquery' in SQL statements?

Answer: Subquery: A query nested in other queries is called a query.
Subquery is also called inner, and the statement containing subquery is called outer query (also called main query).
All subqueries can be divided into two categories, namely correlated subqueries and non-correlated subqueries
(1) Non-correlated subqueries are subqueries independent of external queries. The subqueries are executed once in total. After execution, Pass the value to the outer query.
(2) The execution of the relevant subquery depends on the data of the external query. When the external query executes a row, the subquery is executed once.
Therefore, non-correlated subqueries are more efficient than correlated subqueries

17. What is the difference between char and varchar?

Answer: It is a fixed-length type, and varchar is a variable-length type. The difference between them is:
char(M) type data column, each value occupies M bytes. If a certain length is less than M, MySQL will pad it with space characters on the right. (Padding space characters will be removed during the search operation.) In a varchar(M) type data column, each value only takes up just enough bytes plus one byte to record its length ( That is, the total length is L 1 byte).

18. Mysql storage engine, the difference between myisam and innodb.

Answer: Simple expression:
MyISAM is a non-transactional storage engine; suitable for applications with frequent queries; table locks, no deadlock; suitable for small data, small concurrency
innodb is A storage engine that supports transactions; suitable for applications with a lot of insert and update operations; row locks if designed properly (the biggest difference lies in the level of the lock); suitable for big data and large concurrency.

19. What are the data table types?

Answer: MyISAM, InnoDB, HEAP, BOB, ARCHIVE, CSV, etc.
MyISAM: Mature, stable, easy to manage, fast to read. Some functions do not support (transactions, etc.), table-level locks.
InnoDB: Supports transactions, foreign keys and other features, and data row locking. It takes up a lot of space and does not support full-text indexing, etc.

20. The MySQL database is used as the storage for the publishing system. More than 50,000 entries are added in a day. The operation and maintenance is expected to last three years. How to optimize it?

a. Design a well-designed database structure, allow partial data redundancy, and try to avoid join queries to improve efficiency.
b. Select the appropriate table field data type and storage engine, and add indexes appropriately.
c. Mysql library master-slave reading and writing separation.
d. Find regular tables to reduce the amount of data in a single table and improve query speed.
e. Add caching mechanism, such as memcached, apc, etc.
f. For pages that do not change frequently, generate static pages.
g. Write efficient SQL. For example, SELECT * FROM TABEL is changed to SELECT field_1, field_2, field_3 FROM TABLE.

21. For websites with high traffic, what method do you use to solve the problem of statistics of page visits?

Answer:
a. Confirm whether the server can support the current traffic.
b. Optimize database access.
c. Prohibit external access to links (hotlinking), such as hotlinking of pictures.
d. Control file download.
e. Use different hosts to distribute traffic.
f. Use browsing statistics software to understand the number of visits and perform targeted optimization.

3: Object-oriented part

Back to top

1. What is object-oriented? (Answer with understanding)

Answer: Object-oriented OO = Object-oriented analysis OOA Object-oriented design OOD Object-oriented programming OOP; the popular explanation is that "everything is an object", and all things are regarded as independent objects (units) ), they can complete their own functions instead of being divided into functions like C.

The current pure OO languages ​​are mainly Java and C#. PHP and C also support OO. C is process-oriented.

2. Briefly describe the access rights of private, protected, and public modifiers.

Answer: private: Private members can only be accessed inside the class.

protected: Protected members can be accessed within the class and inherited classes.

public: Public members, completely public, no access restrictions.

3. What is the difference between heap and stack?

Answer: The stack is a memory space allocated during compilation, so the size of the stack must be clearly defined in your code;

The heap is a memory space dynamically allocated during program running. , you can determine the size of heap memory to be allocated based on the running conditions of the program.

4. The main difference between XML and HTML

Answer: (1) XML is case-sensitive, but HTML is not.
(2) In HTML, you can omit closing tags such as
or
if the context clearly shows where the paragraph or list key ends. In XML, the closing tag must not be omitted.
(3) In XML, elements that have a single tag without a matching closing tag must end with a / character. This way the parser knows not to look for the closing tag.
(4) In XML, attribute values ​​must be enclosed in quotation marks. In HTML, quotation marks are optional.
(5) In HTML, you can have attribute names without values. In XML, all attributes must have corresponding values.

5. What are the characteristics of object-oriented?

Answer: Mainly include encapsulation, inheritance, and polymorphism. If it is 4 aspects, add: abstraction.
The following explanation is for understanding:
Encapsulation:
Encapsulation is the basis for ensuring that software components have excellent modularity. The goal of encapsulation is to achieve high cohesion and low coupling of software components to prevent program interdependence. The impact of changes caused by nature.
Inheritance:
When defining and implementing a class, you can do it on the basis of an existing class, and use the content defined by this existing class as your own content, and you can add some new content, or modify the original method to make it more suitable for special needs. This is inheritance. Inheritance is a mechanism for subclasses to automatically share parent class data and methods. This is a relationship between classes that improves the reusability and scalability of software.
Polymorphism:
Polymorphism means that the specific type pointed to by the reference variable defined in the program and the method call issued through the reference variable are not determined during programming, but are determined during the running of the program, that is, Which class instance object a reference variable points to, and which class implements the method call issued by the reference variable, must be determined during the running of the program.
Abstract:
Abstraction is to find out the similarities and commonalities of some things, and then classify these things into a class. This class only considers the similarities and commonalities of these things, and ignores the current topic and Those aspects that are irrelevant to the goal, focus on those aspects that are relevant to the current goal. For example, if you see an ant and an elephant and you can imagine how they are similar, that is abstraction.

6. What are the concepts and differences between abstract classes and interfaces?

Answer: Abstract class: It is a special class that cannot be instantiated and can only be used as a parent class of other classes. Declared using the abstract keyword.
It is a special abstract class and a special class, declared using interface.
(1) The operations of abstract classes are implemented through the inheritance keyword extends, and the use of interfaces is implemented through the implements keyword.
(2) There are data members in the abstract class, which can realize data encapsulation, but the interface has no data members.
(3) Abstract classes can have constructors, but interfaces have no constructors.
(4) Methods of abstract classes can be modified with the private, protected, and public keywords (abstract methods cannot be private), while methods in interfaces can only be modified with the public keyword.
(5) A class can only inherit from one abstract class, and a class can implement multiple interfaces at the same time.
(6) An abstract class can have implementation code for member methods, but an interface cannot have implementation code for member methods.

7. What is a constructor, what is a destructor, and what is its function?

Answer: The constructor (method) is the first method automatically called by the object after the object is created. It exists in every declared class and is a special member method. Its function is to perform some initialization tasks. In Php, __construct() is used to declare the constructor method, and only one can be declared.
The destructor (method) is exactly the opposite of the constructor. It is the last method automatically called by the object before it is destroyed. It is a newly added content in PHP5 that is used to perform some specific operations before destroying an object, such as closing files and releasing memory.

8. How to overload the method of the parent class, give an example

Answer: Overloading means overriding the method of the parent class, that is, using the method in the subclass to replace the method inherited from the parent class, which is also called method rewriting.
The key to overriding the parent class method is to create the same method in the parent class in the subclass, including the method name, parameters and return value type. In PHP, only the names of the methods are required to be the same.

9. What are the commonly used magic methods? Example

Answer: PHP stipulates that methods starting with two underscores (__) are reserved as magic methods, so it is recommended that your function name should not start with __ unless it is to overload an existing magic method. .
__construct() is automatically called when instantiating a class.
__destruct() is automatically called when the class object is used.
__set() is called when assigning a value to an undefined property.
__get() is called when undefined attributes are called.
__isset() Will be called when using isset() or empty() function.
__unset() Will be called when using unset().
__sleep() is called when serializing using serialize.
__wakeup() is called when deserializing using unserialize.
__call() Called when calling a method that does not exist.
__callStatic() calls a static method that does not exist.
__toString() is called when converting an object into a string. Such as echo.
__invoke() Called when trying to invoke an object as a method.
__set_state() Called when using the var_export() function. Accepts an array parameter.
__clone() Called when using clone to copy an object.

10. What do the three keywords $this and self and parent represent respectively? In what situations is it used?

Answer: $this current object
self current class
parent parent class of the current class
$this is used in the current class, use -> to call properties and methods.
self is also used in the current class, but it needs to be called using::.
parent is used in classes.

11. How to define constants in a class, how to call constants in a class, and how to call constants outside a class.

Answer: The constants in the class are also member constants. A constant is a quantity that does not change and is a constant value.
Define constants using the keyword const.
For example: const PI = 3.1415326;
Whether it is within a class or outside a class, the access of constants is different from that of variables. Constants do not need to instantiate objects,
The format for accessing constants is the class name plus the scope operation symbol (double colon) to call.
That is: class name:: class constant name;

12. How to use scope operator::? In what situations is it used?

Answer: Calling class constants
Calling static methods

13. What is the working principle of the __autoload() method?

Answer: The basic condition for using this magic function is that the file name of the class file must be consistent with the name of the class.
When the program is executed to instantiate a certain class, if the class file is not introduced before instantiation, the __autoload() function will be automatically executed.
This function will find the path of the class file based on the name of the instantiated class. When it is determined that the class file does exist in the path of the class file,
execute include or require to load the class, and then the program Continue execution. If the file does not exist in this path, an error will be prompted.
Using the automatically loaded magic function eliminates the need to write many include or require functions.

Four: ThinkPHP part

Back to top

1. Common PHP frameworks

Answer: thinkPHP, yii, ZendFramework, CakePhp, sy

2. How to understand the single entry file in TP?

Answer: ThinkPHP uses a single entrance mode for project deployment and access. No matter what function is completed, a project has a unified (but not necessarily the only) entrance. It should be said that all projects start from the entry file, and the entry files of all projects are similar. The entry file mainly includes:
Define the framework path, project path and project name (optional)
Definition Related constants in debugging mode and running mode (optional)
Load the framework entry file (required)

3. What is the MVC layering in ThinkPHP? (Understanding)

Answer: MVC is a method of separating the logical layer and presentation layer of an application. ThinkPHP is also based on the MVC design pattern. MVC is just an abstract concept and has no particularly clear regulations. The MVC layering in ThinkPHP is roughly reflected in:
Model (M): The definition of the model is completed by the Model class.
Controller (C): Application controller (core controller App class) and Action controller both assume the role of controller. Action controller completes business process control, while application controller is responsible for scheduling control.
View (V): It is composed of View class and template file. The template is 100% separated and can be previewed and produced independently.
But in fact, ThinkPHP does not rely on M or V, which means it can work without a model or view. It doesn’t even rely on C. This is because ThinkPHP also has a master controller on top of Action, the App controller, which is responsible for the overall scheduling of the application. In the absence of C, view V must exist, otherwise it is no longer a complete application.
In short, ThinkPHP's MVC model only provides a means of agile development, rather than sticking to MVC itself.

4. How to optimize SQL? (Students can understand the following explanation, and then just state the general meaning according to their own understanding)

Answer: (1) Choose the correct storage engine
Take MySQL as an example, including There are two storage engines, MyISAM and InnoDB, and each engine has pros and cons.
MyISAM is suitable for applications that require a large number of queries, but it is not very good for a large number of write operations. Even if you just need to update a field, the entire table will be locked, and other processes, even the reading process, cannot operate until the reading operation is completed. In addition, MyISAM is extremely fast for calculations such as SELECT COUNT(*).
The trend of InnoDB will be a very complex storage engine, and for some small applications, it will be slower than MyISAM. But it supports "row locking", so it will be better when there are many write operations. Moreover, it also supports more advanced applications, such as transactions.
(2) Optimize the data type of the field
Remember a principle, the smaller the column, the faster it will be. If a table only has a few columns (such as a dictionary table, configuration table), then we have no reason to use INT as the primary key. It will be more economical to use MEDIUMINT, SMALLINT or a smaller TINYINT. If you don't need to keep track of time, it's much better to use DATE than DATETIME. Of course, you also need to leave enough room for expansion.
(3) Add an index to the search field
The index does not necessarily mean the primary key or the only field. If there is a field in your table that you will always use for searching, it is best to index it. Unless the field you want to search is a large text field, then you should create a full-text index.
(4) Avoid using Select *. The more data is read from the database, the slower the query will become. Moreover, if your database server and WEB server are two independent servers, this will also increase the load of network transmission. Even if you want to query all fields in the data table, try not to use the * wildcard character. Making good use of the built-in field exclusion definitions may bring more convenience.
(5) Use ENUM instead of VARCHAR
The ENUM type is very fast and compact. In fact, it holds a TINYINT, but it appears as a string. In this way, it becomes quite perfect to use this field to make some choice lists. For example, if the values ​​of fields such as gender, ethnicity, department, and status are limited and fixed, you should use ENUM instead of VARCHAR.
(6) Use NOT NULL whenever possible
Unless you have a very special reason to use NULL values, you should always keep your fields NOT NULL. NULL actually requires extra space, and your program will be more complex when you perform comparisons. Of course, this does not mean that you cannot use NULL. The reality is very complicated, and there will still be situations where you need to use NULL values.
(7) Fixed-length tables will be faster
If all fields in the table are "fixed-length", the entire table will be considered "static" or "fixed-length". For example, there are no fields of the following types in the table: VARCHAR, TEXT, BLOB. As long as you include one of these fields, the table is no longer a "fixed-length static table" and the MySQL engine will process it in another way.
Fixed length tables will improve performance because MySQL will search faster. Because these fixed lengths make it easy to calculate the offset of the next data, reading will naturally be faster. And if the field is not of fixed length, then every time you want to find the next one, the program needs to find the primary key.
Also, fixed-length tables are easier to cache and rebuild. However, the only side effect is that fixed-length fields waste some space, because fixed-length fields require so much space regardless of whether you use them or not.

5. How to understand the behavior in ThinkPHP 3.0 architecture three (core behavior driver)?

Answer: Core Behavior Driver
The official abbreviation of TP is: CBD
Core: It is the core code of the framework, an indispensable thing. TP itself is a framework developed based on the MVC idea.
Behavior: Behavior plays a decisive role in the architecture of the new version of ThinkPHP. On the core of the system, many tag extension bits are set, and each tag position can execute its own independent behavior in turn. This is how behavioral extensions were born, and many system functions are also completed through built-in behavioral extensions. All behavioral extensions are replaceable and additive, thus forming the basis for the assembly of the underlying framework.
Driver: database driver, cache driver, tag library driver and template engine driver, as well as external class extensions.
Framework, that is, framework. In fact, it is a semi-finished product of a certain application, a set of components for you to choose and use to complete your own system. To put it simply, you use the stage set up by others and you perform. Moreover, frameworks are generally mature, continuously upgraded software.

6. What is the conventional configuration?

Answer: Convention configuration Previous page Next page Conventions are more important than configurations. This is an important idea that the system follows. The system has a built-in convention configuration file (Conf\convention.php located under the system directory). According to most uses Commonly used parameters are configured by default. Therefore, for the configuration file of the application project, you often only need to configure different or new configuration parameters from the conventional configuration. If you completely adopt the default configuration, you do not even need to define any configuration file.
Conventional configuration files will be automatically loaded by the system and do not need to be loaded in the project.

7. What is SQL injection? (Understanding)

Answer: SQL injection attack is one of the common means used by hackers to attack databases. Some programmers do not judge the legality of user input data when writing code. The injector can enter a database query code in the form and submit it. The program will piece together the submitted information to generate a complete SQL statement, and the server will be deceived. Execute the malicious SQL command. The injector successfully obtains some sensitive data based on the results returned by the program, and even controls the entire server. This is SQL injection.

8. How does ThinkPHP prevent SQL injection? (Understanding)

Answer: (1) Try to use arrays for query conditions, which is a safer way;
(2) If string query conditions must be used as a last resort, use the preprocessing mechanism;
(3) Turn on data field type verification, and you can force conversion of numerical data types; (field type verification has been mandatory since version 3.1)
(4) Use automatic verification and automatic completion mechanisms to perform automatic verification for applications Define filtering;
(5) Use field type checking, automatic verification and automatic completion mechanisms to avoid the entry of malicious data.

9. How to enable debugging mode? What are the benefits of debug mode?

Answer: Turning on the debugging mode is very simple. You only need to add a line of constant definition code to the entry file:

Turn on the debugging mode

After completing the development After the stage is deployed to the production environment, you only need to delete the debug mode definition code to switch to deployment mode. After debugging mode is turned on, the system will first load the system's default debugging configuration file, and then load the project's debugging configuration file. The advantages of debugging mode are: Turn on logging, and any error information and debugging information will be recorded in detail to facilitate debugging; Turn off template caching , template modifications can take effect immediately; record SQL logs to facilitate SQL analysis; turn off field caching, data table field modifications are not affected by caching; strictly check file case (even on Windows platforms), helping you discover Linux deployment problems in advance; can be convenient Used for different stages of the development process, including development, testing and demonstration, etc., independent project configuration files can be configured for different application modes.

10. What configuration modes are supported in TP? priority?

Answer: ThinkPHP has created its own unique hierarchical configuration mode in project configuration. Its configuration level is reflected in: Conventional configuration->Project configuration->Debug configuration->Group configuration-> Extended configuration -> Dynamic configuration
The above is the loading order of configuration files. Because subsequent configurations will overwrite the previous configurations of the same name (without taking effect), the priority order is from right to left.

11. What are the URL patterns in TP? Which is the default?

Answer: ThinkPHP supports four URL modes, which can be defined by setting the URL_MODEL parameter, including normal mode, PATHINFO, REWRITE and compatibility mode.
The default mode is: PATHINFO mode, set URL_MODEL to 1

12. What are the system variables in TP? How to get system variables?

Answer: How to obtain system variables:
Just call the following method in Action:
$this->Method name ("Variable name",["Filter method"],[ "Default value"])

13. What is the difference between D function and M function in ThinkPHP framework?

Answer: The M method instantiates the model without the user defining a model class for each data table. The D method can automatically detect the model class. If a custom model class exists, the custom model class will be instantiated. If not, the custom model class will be instantiated. exists, the M method will be automatically called to instantiate the Model base class. At the same time, models that have been instantiated will not be instantiated repeatedly (single case mode).

5: smarty template engine

Back to top

1. What is the difference between compilation and caching?

The compilation process of smarty is to take the template and replace the tags inside with the corresponding php code. This is the compilation of smarty. In fact, it is the process of mixing php and html.
The cache of smarty needs to be turned on manually. Smarty's cache is to execute the compiled file and generate a static html page at the same time. When you access it again, you will access the html file, so in terms of efficiency, it is higher

2. What is smarty? What are the advantages of Smarty?

Smarty is a PHP template engine written in PHP. The purpose is to separate the PHP program from the artist, so that when the programmer changes the logical content of the program, it will not affect the artist's page design, and when the artist re-modifies the page, it will not affect the page design. It will affect the program logic of the program, which is particularly important in multi-person cooperation projects. (It is also easy to develop multi-style programs)
Advantages of Smarty
1. Fast: compared to other template engines.
2. Compiled type: A program written in smarty must be compiled into a non-template technology PHP file at runtime
3. Caching technology: It can cache the HTML file that the user finally sees into a static HTML Page
4. Plug-in technology: smarty can customize plug-ins.
Not suitable for using smarty
1. Content that needs to be updated in real time. For example, like stock display, it needs to update data frequently
2. Small projects. A small project that requires both an artist and a programmer because of its simplicity

3. Use {$smarty} to retain variables in the template

{$smarty.get.page} //Similar Access $_GET[page]
{smarty.cookies.}
{smarty.post.}
{smarty.session.}
{smarty.server.}

# in the php script ##4. Access variables in php in templates

There are two types of system constants and custom constants in php scripts. These two constants can also be accessed in Smarty templates and do not need to be accessed from Assigned in php, the value of the constant can be directly output as long as the variable is retained through {$smarty}. Example of outputting constants in templates:

{$smarty.const._MY_CONST_VAL}
{$smarty.const.__FILE__}

5, variable mediator

Variable mediator

6. When php queries the mysql database, garbled characters appear when querying the Chinese results. How to deal with it?

1. File properties (save as)

2. File meta (when setting up browser parsing)
3. Encoding settings when connecting to the database
4. Use the header function in the PHP file to determine the encoding

7. Caching mechanism

If caching is enabled, smarty will generate a static html page at the same time. If it does not expire within the set time, when you access it again, you will access the html file, which reduces the need to read the database, so in terms of efficiency, Be higher.

8. Smarty’s assignment and loading template

$Smarty->assign(name,value)

$Smarty->display('index.html')

9. What is the use of marty template technology?

In order to separate php and html, artists and programmers should perform their own duties without interfering with each other.

10. What are the main smarty configurations?

1. Introduce smarty.class.php;

2. Instantiate the smarty object;
3. Remodify the default template path;
4. Remodify the default compiled file Path;
5. Re-modify the default configuration file path;
6. Re-modify the default cache path.
7. You can set whether to enable cache.
8. You can set the left and right delimiters.

11. What details do you need to pay attention to when using smarty?

Smarty is a template engine based on the MVC concept. It divides a page program into two parts for implementation: the view layer and the control layer.

That is to say, smarty technology combines user UI and PHP code separate.
In this way, programmers and artists perform their respective duties without interfering with each other.

12. Pay attention to the following issues when using smarty:

1. Configure smarty correctly. It is mainly necessary to instantiate the smarty object and configure the path of the smarty template file;

2.php page uses assign assignment and display to display the page;
3.php code snippets and all comments are not allowed in the smarty template file. Variables and functions must be included in delimiters.
A.{}
B. foreach
C. if else
D. include
E. Literal

6. Secondary development system (DEDE, ecshop)

Back to top

1. Understanding of secondary development

Secondary development, simply put, is to customize and modify existing software, expand functions, and then Generally speaking, to achieve the functions you want, the core of the original system will not be changed.

2, MVC

Model (model) data processing.

View Template display.
Controller (controller) controls the process.
What is the concept of MVC? What are the main tasks of each level?
MVC (Model-View-Controller) is a software design pattern or programming idea.
M refers to the Model model layer, V is the View layer (display layer or user interface), and C is the Controller layer.
The purpose of using mvc is to separate M and V, so that a program can easily use different user interfaces.
In website development,
The model layer is generally responsible for adding, deleting, modifying, and checking database table information.
The view layer is responsible for displaying page content.
The controller layer plays a regulating role between M and V. , the controller layer decides which method of which model class to call.
After execution, the controller layer decides which view layer to assign the result to.

3. Some warnings and errors appear when accessing the secondary development program after installation.

According to the errors, modify the server configuration parameters and Baidu

4. Functions and template replacement , the addition and modification of functions

are actually used for object-oriented applications, and the replacement of templates is similar to the use of smarty

5. What secondary development things have been used?

Dedecms phpcms ecshop, if you have a good foundation, it will be no problem to learn these basic things.

6. Is it better to do primary development like PHP or secondary development?

Generally, small and medium-sized enterprises use cms system for secondary development, all for the sake of efficiency. Of course, if you want to develop it all at once, that’s fine, as long as you know how to use the framework and have enough time. Large companies develop by teams to avoid copyright issues.

7. In the secondary development process, how are the method accesses between many classes transmitted?

It is not class inheritance but object combination. Pass the instantiated object through global

8. If dedecms changes the directory, a certain item in the background cannot be entered. How to solve it?

Change the background core settings to the current project directory name

9. Do you understand the custom model in dedecms?

There is the concept of content model in the DreamWeaver system. Different content models can be used to build sites with different content forms. The system comes with the following models: ordinary articles, photo albums, software, and products. , classified information, special topics. Through the system's own model, we can use it to build different types of sites. For example, you can use an atlas to build a picture site, and use a software model to build a software download site.
Of course, the above models that come with the system are called system models. Users can define some models by themselves, such as books, music albums, etc. Only by customizing these models can they build sites with more content forms.
It is equivalent to us automatically adding the table structure to adapt to changes in current needs

10. Concepts in dede, designing and using templates, you must understand the following concepts

1. Section (cover) template:
refers to the template used by the website homepage or the more important column cover channel. It is generally named with "index_identification ID.htm". In addition, a single page or custom tag defined by the user can also be used. Select whether to support section template tags. If supported, the system will use the section template tag engine to parse before outputting the content or generating a specific file.
2. List template:
refers to the template for the list of all articles in a certain column of the website, generally named with "list_identification ID.htm".
3. File template:
Represents the template of the document viewing page, such as the article template, which is generally named with "article_identification ID.htm".
4. Other templates:
The general system generally includes templates: home page template, search template, RSS, JS compilation function template, etc. In addition, users can also customize a template to create any file.

11. How many tags are used in dede?

List, content and other tags can only be used within their scope, list tags can only be used in lists, and content tags can only be used in content tags.
Global tags can be used in all pages

12. Familiar with common class libraries

(for example: dedesql.class.php); familiar with system function libraries (common.func.php) ; Familiar with the custom function library (extend.func.php); Familiar with the front-end entry file (common.inc.php)

7. WeChat public platform development

Return to top

1. WeChat operating mechanism

What language is used to communicate between the official account and php:Xml
How to receive the official account data in Weixin.php:
$postStr = $GLOBALS["HTTP_RAW_POST_DATA "];//Receive data XML data

2. Message type

WeChat currently provides 7 basic message types, which are:
(1) Text message (text);
(2) Picture message (image);
(3) Voice (voice)
(4) Video (video)
(5) Geographical location (location);
(6) Link message (link);
(7) Event push (event)
type. Master the data transfer format when sending different message types

3. The function to read the entire file into a string is

File_get_contents

4. Commonly used functions

The function that parses xml data into objects is
simplexml_load_string( )
The function that converts strings into arrays is ___ explode________, and the function that converts arrays into strings is ____implode________.
Encoding The string of the URL string is ____urlencode________.

5. The function of the Sprintf function

You can check the manual for this.

6. Why is the WeChat official account unable to provide services?

(1) Network reason, data interface reason
(2) Code error, how to guess the reason
Check where to modify, if the code is correct
You can output the data and take a look. Use php to operate files
$myfile = fopen("newfile.txt", "w");
$txt ="aaaaaaaaaa";
fwrite($myfile, $txt);
fclose( $myfile);

7. Custom menu event push

Click
Click the jump link
Scan the code to push the event
Scan the code to push and pop up
The event that pops up the system to take pictures and send pictures
The event that pops up the WeChat album sender
The event that pops up the geographical location selector

8. The role of token

Security mechanism verification , used for security verification between WeChat server and PHP server

9. The role of Appid and secrect

When requesting the api interface (such as menu operation), you need to pass the two values ​​​​of appid and secrect , used to obtain the authorization code of the application

8. Description of the technology you master

1. Take PHP MYSQL as the direction, be proficient in smarty template engine, ThinkPHP framework, WeChat public platform development, DEDE, ecshop and other secondary development systems, and have a certain understanding of object-oriented; in terms of database, be proficient in MYSQL and MSSQL and other databases; familiar with PHP development under Linux
2. Front-end technology: proficient in DIV CSS web page layout, javascript, JQuery framework, AJAX technology, photoshop image processing
3. One year of project development experience, using smarty Developed 'XXXXXXXX', ThinkPHP developed 'XXXXXXXX', used WeChat public platform to develop the public account of 'Employment Service Network', used DreamWeaver system to develop corporate website, etc.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template