Summary of PHP Professional Interview Questions (Theory)

 Watson Blog October 15, 2017 00:15:28 Web hodgepodge comment two hundred and eighty-three Reading mode

1、 Basic PHP

1. One of the advantages of PHP 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 limited by the operating system, so it is called cross platform

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

Get and post;

difference:

1. Get gets data from the server and post sends data to the server

2. The Get value is visible in the url, and the post is not visible in the url

3. The Get value is generally within 2KB, and the post value size can be set in php.ini

4. Get security is not low, post security is high, but execution efficiency is higher than Post

Suggestion:

1. The security of the get type is worse than that of the post type. It is recommended to use the post data submission type to contain confidential information;

2. Get is recommended for data query; It is recommended to add, modify or delete data in Post mode;

Baidu uses the get method, because you can see from its URL

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

Framework: There are many frameworks, such as zendframe, CI, Yii, etc. We learned thinkphp

Template engine: there are many, which are in textbooks. What we have learned is smart

Systems: There are many, such as Kangsheng products (uchome, supersite, discuzX, etc.), Imperial System, DEDE (dream weaving), echo, etc. We have learned about DEDECMS, Echo

4. What are your web front-end technologies?

Proficient in DIV+CSS web layout, javascript, JQuery, AngularJS, bootstrap, photoshop image processing;

5. What are the advantages of AJAX?

Ajax is an asynchronous transmission technology, which can be implemented through javascript or JQuery framework to achieve local refresh, reduce the pressure on the server and improve the user experience

6. Security is very important to a set of programs. What security mechanisms should be paid attention to in development?

① Prevent remote submission;

② Prevent SQL injection and filter special codes;

③ Prevent the registration machine from watering and use the verification code;

7. How to improve the efficiency of program development?

① Optimize the SQL statement. Try not to use select * in the query statement; Less subqueries can be replaced by table joins; Use less fuzzy query; ② Create index in data table; ③ Generate cache for data frequently used in programs;

8. Can PHP be used with other databases?

PHP is the best match with the MYSQL database. Of course, PHP can also be used with other databases, such as MSSQL. PHP has reserved functions to operate MSSQL, which can be used as long as it is enabled

9. Now, MVC three-tier structure is often used in programming. What are the three tiers of MVC and what are their advantages?

The three layers of MVC refer to business model, view and controller respectively. The controller layer calls the model to process data, and then maps the data to the view layer for display. The advantages are: ① code reusability can be realized to avoid code redundancy; ② The implementation code of M and V is separated, so that the same program can use different representations

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 as data transmission by multiple languages

The function that handles the json format in PHP is json_decode (string $json [, bool $assoc]), which accepts a string in the JSON format and converts it into a PHP variable. The parameter json is a string in the json string format to be decoded. Assoc When this parameter is TRUE, array will be returned instead of object;

Json_encode: convert PHP variables to json format

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

① Both echo and print can output. The difference is that echo is not a function and has no return value, while print is a function that has a return value. Therefore, it is relatively faster to output echo only, while print_r is usually used to print information about variables and is usually used in debugging.

② Print is a print string

③ Print_r is to print composite types such as array objects

12. What is the difference between SESSION and COOKIE?

① Storage location: session is stored in the server and cookie is stored in the browser

② Security: session security is higher than cookie

③ Session is a 'session service', which needs to be enabled when using. Cookies do not need to be enabled, but can be used directly

13. B/S principle?

B/S (Browser/Server) structure is browser / Server structure. Users can access the Internet On by Web The text, data, image, animation, video on demand, sound and other information generated by the server Web The server can connect with the database server in various ways, and a large amount of data is actually stored in the database server. from Web Download the program from the server to the local for execution. If the instructions related to the database are encountered during the download process Web The server gives it to the database server to interpret the execution and returns it to the Web The server, Web The server returns it to the user. In this structure, many networks are connected together to form a huge network, namely the global network. Each enterprise can build its own Internet

From the user's operation, the user submits a form operation on the browser page, sends a request to the server, and the server receives and processes the request, and then returns the data (web page files, pictures, sounds, etc.) requested by the user to the browser. This time, the request is completed. As shown below:

 Summary of PHP Professional Interview Questions (Theory)

14. Common functions for PHP to handle arrays? (Focus on the 'parameter' 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 (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 an array in reverse order;

⑦ Array_unique() deletes duplicate values in the array;

⑧ In_array() checks whether the specified value exists in the array;

15. Common functions for PHP to process strings?

① Trim () removes the blank characters and other characters on both sides of the string; ② Substr_replace() replaces part of a string with another string; ③ Substr_count() calculates the number of substrings 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() looks for the last occurrence of a string in another string; ⑨ Strstr() looks for the first occurrence of a string in another string (case sensitive); Strrev() inverts the string; Strlen() returns the length of the string; Str_replace() replaces some characters in the string (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 for cutting Chinese and English

16. Common functions of PHP processing time?

Date_default_timezone_get() returns the default time zone.

Date_default_timezone_set() sets the default time zone.

Date() format the local time/date.

Getdate() returns date/time information.

Gettimeofday() returns the current time information.

Microtime() returns the microseconds of the current time.

Mktime () returns a Unix timestamp of a date.

Strtotime() parses the date or time description of any English text into a Unix timestamp.

Time() returns the Unix timestamp of the current time.

17. Is PHP a common function for database processing?

Please refer to the php manual. This is very important

18. Common functions for PHP operating files?

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

19. Common functions of PHP operating directory (folder)?

① Open directory; ② Delete directory; ③ Read directory; ④ Create directory; ⑤ Modify the directory; ⑥ Close directory and so on. This is very important. It is often used to create or delete the directory of uploaded files, create or delete the directory of cache and static pages. Please refer to the PHP manual and check carefully

2、 Database section

1. The common relational database management system products are?

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

2. What parts does the SQL language include? What are the operation keywords in each part?

Answer: SQL language includes 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 are integrity constraints?

A: Data integrity refers to the accuracy and reliability of data.

It is divided into the following four categories:

1) Entity integrity: specifies that each row of the table is a unique entity in the table.

2) Domain integrity: the columns in the table must meet certain data type constraints, including value range, precision, etc.

3) Reference integrity: refers to that the data of primary key and foreign key of two tables should be consistent, which ensures the consistency of data between tables and prevents data loss or meaningless data from spreading in the database.

4) User defined integrity: different relational database systems often need some special constraints according to their application environments. User defined integrity refers to the constraints of a specific relational database, which reflects the semantic requirements that a specific application must meet.

Table related constraints: including column constraints (NOT NULL) and table constraints (PRIMARY KEY foreign key、check、UNIQUE) 。

4. What is a transaction? And its characteristics?

Answer: Transaction is a series of database operations and the basic logical unit of database application.

Transaction characteristics:

(1) Atomicity: that is, indivisibility. Transactions are either all executed or not all executed.

(2) Consistency or serializability. The execution of transactions makes the database change from one correct state to another

(3) Isolation. Before the transaction is correctly committed, it is not allowed to provide any changes to the data by the transaction to any other transaction,

(4) Persistence. After the transaction is correctly committed, its results will be permanently saved in the database. Even if there are other failures after the transaction is committed, the transaction processing results will also be saved.

Or to understand it this way:

A transaction is a grouping of SQL statements bound together as a logical unit of work. If any statement fails to operate, the entire operation will fail. Later, the operation will roll back to the pre operation state, or there will be a node on it. You can use transactions to ensure that they are either executed or not executed. To consider a group statement as a transaction, you need to pass the ACID test, that is, atomicity, consistency, isolation and persistence.

5. What is a lock?

Answer: The database is a shared resource used by multiple users. When multiple users access data concurrently, multiple transactions will access the same data at the same time in the database. If concurrent operations are not controlled, incorrect data may be read and stored, and database consistency may be damaged.

Locking is a very important technology for database concurrency control. Before a transaction operates on a data object, it sends a request to the system to lock it. After locking, the transaction has some control over the data object. Other transactions cannot update the data object until the transaction releases the lock.

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 with the same functions as a physical table. A view can be added, modified, queried, and operated. A view is usually a subset of rows or columns in one table or multiple tables. Changes to the view do not affect the base table. It makes it easier for us to obtain data, compared with multi table queries.

Cursor: effectively processes the queried result set as a unit. A 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 modify the current row of the result set. Generally, cursors are not used, but they are very important when processing data one by one.

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

Answer: A stored procedure is a precompiled SQL statement, which has the advantage of allowing modular design, that is, it only needs to be created once, and then it can be called multiple times in the program. If an operation requires multiple SQL executions, using stored procedures is faster than executing simple SQL statements. You can use a command object to call the stored procedure.

8. What is the function of index? What are its advantages and disadvantages?

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

9. How to understand the three paradigms?

Answer: The first normal form: 1NF is an atomic constraint on attributes, which requires attributes to be atomic and cannot be decomposed again;

The second normal form: 2NF is the uniqueness constraint on records, which requires records to have a unique identifier, that is, the uniqueness of entities;

The third normal form: 3NF is a constraint on field redundancy, that is, any field cannot be derived from other fields. It requires that fields have no redundancy..

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

Answer: A basic table is an independent table. In SQL, one relationship corresponds to one table. A view is a table exported from one or more basic tables. The view itself is not stored in the database independently, it is a virtual table

11. Describe the advantages of the view?

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 can provide security protection for confidential data.

12. What does NULL mean

Answer: NULL means UNKNOWN (unknown): it does not mean "" (empty string). Any comparison of the value of NULL will produce a NULL value. You cannot compare any value with a NULL value and logically expect an answer.

Use IS NULL to judge NULL

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

Difference between primary key, foreign key and index

definition:

Primary key -- uniquely identifies a record. It cannot be duplicate or empty

Foreign key -- the foreign key of a table is the primary key of another table, and the foreign key can have duplicate or null values

Index -- This field has no duplicate value, but can have a null value

effect:

Primary key -- used to ensure data integrity

Foreign key -- used to establish relations with other tables

Indexing is to improve the speed of query sorting

number:

Primary key -- there can only be one primary key

Foreign key -- a table can have multiple foreign keys

Index -- 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 limit, which is defined in the database table, is used to limit the values entered in this column.

Triggers can also be used to limit the acceptable values of fields in database tables. However, this method requires that triggers be defined in tables, which may affect performance in some cases.

15. What are the methods for optimizing SQL statements? (Select several)

(1) In the Where clause: the connection between where tables must be written before other Where conditions, and the 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 instead of IN, and use NOT EXISTS instead of 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, try to avoid full table scanning. First, consider building indexes on the columns involved in where and order by.

(6) Try to avoid null value judgment on the field in the where clause, or the engine will give up using the index and perform a full table scan

(7) You should try to avoid performing expression operations on fields in the where clause, which will cause the engine to give up using indexes and perform a full table scan

16. What is the difference between 'related sub query' and 'non related sub query' in the SQL statement?

Answer: Sub query: It refers to queries nested in other queries.

Sub query is also called internal, and the statement containing sub query is called external query (also called main query).

All sub queries can be divided into two categories, namely, related sub queries and unrelated sub queries

(1) Non related sub query is a sub query independent of external query. The sub query is executed once in total, and the value is passed to the external query after execution.

(2) The execution of the related sub query depends on the data of the external query. Each row of the external query is executed, and the sub query is executed once.

Therefore, non related subqueries are more efficient than related subqueries

17. What is the difference between char and varchar?

Answer: It is a fixed length type, while varchar is a variable length type. Their differences are:

In the char (M) data column, each value occupies M bytes. If a length is less than M, MySQL will fill in the space characters on its right side. (Those filled in space characters will be removed in the retrieval operation.) In the varchar (M) type data column, each value only occupies just enough bytes plus a byte to record its length (that is, the total length is L+1 bytes)

18. MySQL's storage engine, the difference between Myisam and Innodb.

A: Simple expression:

MyISAM is a non transactional storage engine; Suitable for applications with frequent queries; Table lock, no deadlock; Suitable for small data and small concurrency

Innodb is a storage engine that supports transactions; For applications with more insertion and update operations; If the design is reasonable, it is row lock (the biggest difference lies in the lock level); It is suitable for big data and big concurrency.

19. What are the data table types

A: MyISAM, InnoDB, HEAP, BOB, ARCHIVE, CSV, etc.

MyISAM: mature, stable, easy to manage, fast to read. Some functions do not support table level locks (such as transactions).

InnoDB: supports transaction, foreign key and data row locking. It takes a large amount of space and does not support full-text indexing.

20. MySQL database is used as the storage of the publishing system, with an increase of more than 50000 items a day. It is expected to be operated and maintained for three years. How to optimize it?

a. A well designed database structure allows partial data redundancy, avoids join queries as far as possible, and improves efficiency.

b. Select the appropriate table field data type and storage engine, and add indexes appropriately.

c. The mysql library is separated from read and write.

d. Find rules to divide tables, and reduce the amount of data in a single table to improve query speed.

e. Add caching mechanisms, such as memcached and APC.

f. Generate static pages for pages that are not changed frequently.

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 large traffic, what methods do you use to solve the problem of page traffic statistics?

Answer: a Confirm whether the server can support the current traffic.

b. Optimize database access.

c. Prohibit external access links (piracy), such as picture piracy.

d. Control file download.

e. Use different host shunts.

f. Use the browsing statistics software to understand the number of visits and make targeted optimization.

3、 Object oriented part

1. What is object-oriented? (Understanding the answer)

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". All things are regarded as independent objects (units) that can complete their own functions, rather than being divided into functions like C.

Now pure OO languages are mainly java and C #. PHP and C++also support OO. C is process oriented.

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

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

Protected: protect members, which can be accessed inside this class and in inherited classes.

Public: public member, fully open, without access restrictions.

3. What is the difference between heap and stack?

Answer: Stack is the memory space allocated during compilation, so your code must have a clear definition of the size of the stack;

Heap is the dynamically allocated memory space during the running of the program. You can determine the size of the heap memory to be allocated according to the running of the program.

4. Main differences between XML and HTML

Answer: (1) XML is case sensitive, and HTML is not.

(2) In HTML, if the context clearly shows where the paragraph or list key ends, you can omit closing tags such as</p>or</li>. In XML, the closing tag must not be omitted.

(3) In XML, elements with a single tag but no matching closing tag must end with a/character. In this way, the analyzer knows not to look for the end tag.

(4) In XML, attribute values must be enclosed in quotation marks. In HTML, quotation marks can be used or not.

(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: There are encapsulation, inheritance and polymorphism. If there are four aspects, add: abstract.

The following explanation is for understanding:

Encapsulation:

Encapsulation is the basis to ensure that software components have excellent modularity. The goal of encapsulation is to achieve high cohesion and low coupling of software components and prevent the impact of changes caused by program interdependence

Inheritance:

When defining and implementing a class, it can be based on an existing class, take the content defined by the existing class as its own content, and add some new content, or modify the original method to make it more suitable for special needs, which is inheritance. Inheritance is a mechanism for subclasses to automatically share parent class data and methods, which is a relationship between classes and improves the reusability and extensibility of software.

Polymorphism:

Polymorphism means that the specific type that the reference variable defined in the program points to and the method call issued through the reference variable are not determined during programming, but are determined during program operation, that is, which class instance object a reference variable will point to, and which class the method call issued by the reference variable is implemented in, The decision must be made during the run by 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 will ignore those aspects unrelated to the current theme and goal, and focus on those aspects related to the current goal. For example, when you see an ant and an elephant, you can imagine their similarities, 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 the parent class of other classes. Declare using the abstract keyword.

It is a special abstract class and also a special class, which is declared using interface.

(1) The operation of abstract class is realized by inheriting the keyword extends, while the use of interface is realized by implementing the keyword.

(2) Abstract classes have data members, which can encapsulate data, but the interface has no data members.

(3) Abstract classes can have constructors, but interfaces have no constructors.

(4) The methods of abstract classes can be modified by private, protected, and public keywords (abstract methods cannot be private), while methods in interfaces can only be modified by public keywords.

(5) A class can only inherit from one abstract class, and a class can implement multiple interfaces at the same time.

(6) Abstract classes can have implementation code of member methods, while interfaces cannot have implementation code of member methods.

7. What are constructors, destructors, and their functions?

Answer: The constructor (method) is the first method automatically called by the object after the object is created. It exists in each declared class and is a special member method. The function is to perform some initialization tasks. Php uses __construct() to declare construction methods, and only one can be declared.

The destructor (method) is the last method automatically called by the object before the object is destroyed. The newly added content in PHP 5 is used to perform some specific operations, such as closing files and freeing memory, before destroying an object.

8. How to overload the methods of the parent class, with examples

Answer: Overloading means overwriting the method of the parent class, that is, replacing the inherited method from the parent class with the method in the child class. It 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 child class, including the method name, parameter and return value type. PHP only requires the same method name.

9. What are the common magic methods? Example

Answer: PHP stipulates that methods starting with two underscores (__) are reserved as magic methods, so it is recommended that function names should not start with __, unless it is to overload existing magic methods.

__Construct() is called automatically when the class is instantiated.

__The destruct () class object is automatically called at the end of use.

__Set () is called when an undefined attribute is assigned a value.

__Get () is called when calling an undefined property.

__Isset() is called when isset() or empty() functions are used.

__When unset() is used, it will be called.

__Called when sleep () is serialized using serialize.

__Wakeup() is called when deserialize is used.

__Call () is called when calling a non-existent method.

__CallStatic() calls a static method that does not exist.

__ToString() is called when the object is converted to a string. For example, echo.

__Invoke () is called when trying to call an object as a method.

__Set_state() is called when the var_export() function is used. Accept an array parameter.

__Clone () is called when clone is used to copy an object.

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

Answer: $this current object

Self current class

Parent The parent 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 the:: call is required.

The parent is used in the class.

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

Answer: A constant in a class is also a member constant. A constant is a constant value that does not change.

Define constants using the keyword const

For example, const PI=3.1415326;

Whether inside or outside the class, the access of constants and variables are different. Constants do not need to instantiate objects,

The format of accessing constants is called by the class name plus the scope operation symbol (double colon).

Namely: class name: class constant name;

12. How to use the scope operator "::"? In what occasions?

Answer: Call class constant

Calling static methods

13. How does the __autoload() method work?

Answer: The basic condition for using this magic function is that the file name of the class file should be consistent with the name of the class.

When the program executes to instantiate a class, if the class file is not imported before instantiation, the __autoload() function will be automatically executed.

This function will find the path of the class file according to the name of the instantiated class. When it is determined that the class file does exist in the class file path, it will execute include or require to load the class, and then the program will continue to execute. If the file does not exist in the path, an error will be prompted. It is unnecessary to write many include or require functions using the magic function of automatic loading.

4、 ThinkPapp section

1. Common PHP frameworks

A: thinkPHP

Laravel

yii

ZendFramework

CakePHP

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

Answer: ThinkPHP uses a single entry mode for project deployment and access. No matter what functions are completed, a project has a unified (but not necessarily unique) entry. It should be said that all projects start from the entry file, and the entry file of all projects is similar. The entry file mainly includes:

Define framework path, project path, and project name (optional)

Define related constants for debug mode and run mode (optional)

Load the frame entry file (required)

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

Answer: MVC is a method to separate the logical layer and presentation layer of an application. ThinkPHP is also based on the MVC design pattern. MVC is just an abstract concept without specific provisions. The MVC hierarchy in ThinkPaP is roughly reflected in:

Model: The definition of the model is completed by the Model class.

Controller (C): both the application controller (core controller App class) and the Action controller assume the role of controller. The Action controller completes business process control, while the 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.
In fact, ThinkPHP does not rely on M or V. That is to say, it can work without models or views. It doesn't even rely on C, because ThinkPaPHP also has a master controller on top of Action, namely the App controller, which is responsible for the overall scheduling of applications. In the absence of C, there must be view V, otherwise it is no longer a complete application.

In a word, ThinkPHP's MVC mode 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 give the general meaning according to their own understanding.)

Answer: (1) Select the correct storage engine

Take MySQL for example. There are two storage engines, MyISAM and InnoDB. Each engine has advantages and disadvantages.

MyISAM is suitable for some applications that need a lot of queries, but it is not very good for many write operations. Even if you just need to update a field, the entire table will be locked, while other processes, even the read process, cannot operate until the read operation is completed. In addition, MyISAM's calculation of SELECT COUNT (*) is extremely fast.

The trend of InnoDB will be a very complex storage engine. For some small applications, it will be slower than MyISAM. However, it supports "row locking", so it is better when there are more write operations. In addition, it also supports more advanced applications, such as transactions.

(2) Optimize the data type of the field

Remember the principle that smaller columns will be faster. If a table only has several columns (such as dictionary table and configuration table), there is no reason to use INT as the primary key. It is more economical to use MEDIUMINT, SMALLINT or smaller TINYINT. If you don't need to record time, DATE is much better than DATETIME. Of course, you also need to leave enough space for expansion.

(3) Add an index to the search field

An index is not necessarily a primary key or a unique field. If there is a field in your table that you will always use for searching, it is better to index it. Unless the field you want to search is a large text field, you should build a full-text index.

(4) Avoid using Select* The more data is read from the database, the slower the query will become. In addition, 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 the fields in the data table, try not to use the * wildcard. 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 stores TINYINT, but it appears as a string. In this way, it is quite perfect to use this field to make a list of options. For example, the values of such fields as gender, nationality, department and status are limited and fixed, so you should use ENUM instead of VARCHAR.

(6) Use NOT NULL whenever possible

Unless you have a 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 compare. Of course, this doesn't mean that you can't use NULL. The reality is very complicated. There are still some cases where you need to use a NULL value.

(7) Fixed length tables will be faster

If all fields in the table are "fixed length", the whole table will be considered as "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 not a "fixed length static table". In this way, the MySQL engine will use another method to process it.

Fixed length tables will improve performance, because MySQL searches faster. Because these fixed length tables are easy to calculate the offset of the next data, they will read quickly. If the field is not fixed length, the program needs to find the primary key every time it finds the next one.

Also, fixed length tables are easier to cache and rebuild. However, the only side effect is that fixed length fields will waste some space, because fixed length fields need to allocate so much space whether you use them or not.

5. How to understand the behavior in ThinkPaPHP 3.0 architecture III (core+behavior+driver)?

Answer: core+behavior+drive

TP official abbreviation: CBD

Core TP is the core code of the framework. It is indispensable. TP itself is a framework developed based on MVC ideas.

Behavior : Behavior plays an important 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. Therefore, behavior extension is born, and many system functions are completed through built-in behavior extension. All behavior extensions are replaceable and incremental, which forms the basis for the assembly of the underlying framework.

Driver : Database driver, cache driver, tag library driver, template engine driver, and external class extension.

Framework. In fact, it is a semi-finished product of an application, a group of components for you to select and complete your own system. In short, you can use the stage set up by others to perform. Moreover, the framework is generally mature and constantly upgraded software.

6. What is a convention configuration?

Answer: It is an important idea for the system to follow that convention configuration is more important than configuration on the previous page and the next page. The system has a built-in convention configuration file (Conf convention. php under the system directory). Common parameters are configured by default according to most uses. Therefore, for the configuration file of an application project, it is often only necessary to configure different or newly added configuration parameters from the conventional configuration. If you completely adopt the default configuration, you don't even need to define any configuration file.

The convention configuration file will be automatically loaded by the system without loading in the project.

7. What is SQL injection? (Understanding)

Answer: SQL injection attack is one of the common means for hackers to attack databases. Some programmers did not judge the validity of the user's input data when writing the code. The injector can enter a database query code in the form and submit it. The program pieced together the submitted information to generate a complete SQL statement. The server was deceived and executed the malicious SQL command. According to the results returned by the program, the injector can successfully obtain some sensitive data and even control the entire server, which is called SQL injection.

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

Answer: (1) Try to use array as the query condition, which is a safer way;

(2) If you have to use string query conditions, use the preprocessing mechanism;

(3) Enable data field type validation to perform forced conversion on numeric data types; (Since version 3.1, field type verification has been enforced.)

(4) Use automatic verification and automatic completion mechanism to carry out customized filtering for applications;

(5) Use field type check, automatic verification and automatic completion mechanisms to avoid malicious data input.

9. How to turn on debug mode? What are the benefits of debug mode?

Answer: It is easy to open the debug mode. You only need to add a line of constant definition code in the entry file:

 <? php //Turn on debug mode define('APP_DEBUG', true); //Load the framework entry file require './ThinkPHP/ThinkPHP.php';

After the development phase is deployed to the production environment, just delete the debug mode definition code to switch to the deployment mode. After the debugging mode is enabled, the system will first load the default debugging configuration file of the system, and then load the debugging configuration file of the project. The advantages of the debugging mode are:

Turn on logging, and any error information and debugging information will be recorded in detail for debugging;

Close the template cache, and the template modification can take effect immediately;

Record SQL logs to facilitate SQL analysis;

Turn off the field cache, and the modification of data table fields will not be affected by the cache;

Strictly check the file case (even on Windows platforms) to help you find Linux deployment problems in advance;

It can be easily used in different stages of the development process, including development, testing, demonstration and any other needs. Different application modes can be configured with independent project configuration files.

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

A: ThinkPHP has created its own unique hierarchical configuration mode in project configuration, and its configuration levels are reflected in:

Routine Configuration ->Project Configuration ->Debugging Configuration ->Grouping Configuration ->Extension Configuration ->Dynamic Configuration

The above is the loading order of the configuration file. Since the later configuration will overwrite the previous configuration with the same name (if it does not take effect), the priority is from right to left.

11. What are the URL modes in TP? What 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, and the URL_MODEL is set to 1

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

Answer: How to obtain system variables:

 Summary of PHP Professional Interview Questions (Theory)

Just call the following methods 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: M method does not require users to define model classes for each data table to instantiate the model. D method can automatically detect model classes. If there are user-defined model classes, instantiate the user-defined model classes. If there are no user-defined model classes, M method will be automatically called to instantiate the base model classes. At the same time, the instantiated model will not be de instantiated repeatedly (single instance mode).

5、 Smart template engine

1. What is the difference between compiling and caching?

The compilation process of smart is to take the template and replace the tag with the corresponding php code. This is the compilation of smart, which is actually the process of mixing php and html

Smart cache needs to be opened manually. Smart cache is to generate a static html page after the compiled file is executed. When you visit again, you will access the html file, so it is more efficient

2. What is smart? What are the benefits of Smarty?

Smarty is a PHP template engine written in PHP to use PHP program is separated from art , so that when the programmer changes the logic content of the program, it will not affect the page design of the artist, and when the artist re modifies the page, it will not affect the program logic of the program, which is particularly important in the project of many people. (It is also easy to develop programs in multiple styles)

Smarty Benefits

1. Fast: Compared with other template engines.

2. Compiled: Programs written with smart should be compiled into a non template PHP file at runtime

3 Cache technology: it can cache the HTML file that the user finally sees into a static HTML page

4. Plug in technology: Smart can customize plug-ins.

Where Smart is not suitable

1. Contents to be updated in real time. For example, like stock display, it needs to update data frequently

2. Small projects. Small project: a project where the designer and programmer are the same because the project is simple

3. Use {$smart} to reserve variables in the template

 {$smart. get. page}//Similar to accessing $_GET [page] in a php script {smarty.cookies.} {smarty.post.} {smarty.session.} {smarty.server.}

4. Accessing variables in php in templates

In php script, there are two kinds of constants: system constant and custom constant. Similarly, these two kinds of constants can also be accessed in Smarty template, and do not need to be allocated from php. As long as {$smart} reserves variables, you can directly output constant values. Example of outputting constants in a template:

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

5. Variable Mediator

 {$var|modifier1|modifier2|........} <{$str}><br> <{$str | capitalize}><{* capitalize *}><br> <{$str | upper}><{* all uppercase *}><br> <{$str | lower}><{* All lower case *}><br> <{$str | lower | upper}><{* All uppercase, adjust from left to right *}><br> <{$leg | truncate}><{* String truncation, default 80 characters *}><br> <{$leg | truncate: 10}><{* String truncation, the first 10 characters, including... three characters *}><br>

6. When PHP queries the MySQL database, garbled code appears when querying Chinese results. How to solve????

1. File attribute (save as another)

2. File meta (when setting browser resolution)

3. Code setting when connecting to the database

4. Use the header function in the PHP file to determine the code

7. Cache mechanism

If caching is enabled, Smart will generate a static html page at the same time. If the set time does not expire, when you visit again, you will access the html file, reducing the reading of the database, so it is more efficient.

8. Smart assignment and loading template

 $Smarty->assign(name,value) $Smarty->display(‘index.html’)

9. What is the purpose of smart template technology?

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

10. What are the main smart configurations?

1. Introduce smarty.class.php;

2. Instantiate the smart object;

3. Modify the default template path again;

4. Revise the default path of the compiled file;

5. Modify the default configuration file path again;

6. Modify the default cache path again.

7. You can set whether to enable cache.

8. Left and right delimiters can be set.

11. What details should we pay attention to when using Smart?

Smarty is a template engine based on MVC concept, which divides a page program into two parts to realize: view layer and control layer. That is to say, smart technology separates user UI from php code. In this way, programmers and artists perform their own duties without interfering with each other.

12. Pay attention to the following issues during the application of smart:

1. Configure smart correctly. Mainly instantiate the smart object and configure the path of the smart template file;

2. In the php page, use assign to assign values and display to display the page;

3. PHP code segments are not allowed in smart template files. All comments, variables, and functions must be included in the delimiter.

A.{}

B. foreach

C. if else

D. include

E. Literal

6、 Secondary development system (DEDE, ecshop)

1. Understanding of secondary development

The secondary development is simply to customize and modify the existing software, expand the function, and then achieve the desired function. Generally speaking, the original system kernel will not be changed.

2. MVC

Model data processing.

The View template displays.

The Controller controls the flow.

What is the concept of MVC? What are the main tasks of each layer?

MVC (model view controller) is a software design pattern or programming idea.

M refers to the Model layer, V refers to the View layer (display layer or user interface), and C refers to the Controller layer.

The purpose of using mvc is to separate M from 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 querying 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 results to.

 

3. There are some warnings and errors when accessing the secondary development program after installation

Modify the server configuration parameters and Baidu according to the error

4. Replacement of functions and templates, addition and modification of functions

In fact, it is used for object-oriented applications and template replacement, similar to the use of smart

5. What have you used for secondary development?

Dedecms phpcms ecshop, If you have a good foundation, you will have no problem learning these basic things.

6. Is it better to develop PHP once or twice?

Generally, small and medium-sized enterprises use cms system for secondary development, all for efficiency. Of course, if you want to develop once, you can use the framework and have enough time. Large enterprises are developed by teams to eliminate copyright issues.

7. What is the method access between many classes in the secondary development process?

It is not class inheritance but object combination, and the instantiated object is passed in through global

8. If dedecms changes the directory, how to solve the problem that an item in the background cannot enter?

The current project directory name is modified in the background core settings

9. Understanding of user-defined models in dedecms?

In the dream weaving system, there is the concept of content model. Different content models can be used to build sites with different content forms. The system has the following models: ordinary articles, atlases, software, commodities, classified information, and topics. Through the system's own model, we can use it to build different types of sites. For example, we can use atlas to build a photo station, and software model to build a software download site.

Of course, the above models attached with the system are called system models. Users can define some models by themselves, such as books, music albums, etc. Only by defining these models can they build more content forms of websites.

It is equivalent to that we have automatically added a table structure to adapt to the changes in current requirements

10. The following concepts must be understood when designing and using templates in dede

1. Module (cover) template:

It refers to the template used by the website homepage or the important column cover channel, which is generally named with "index_Identification ID. htm". In addition, the single page or user-defined tag defined by the user can also choose whether to support plate template tag. If so, the system will use the plate template tag engine to parse before outputting content or generating specific files.

2. List template:

It refers to the template of the list of all articles in a column of the website. It is generally named "list_Identification ID. htm".

3. File template:

A template representing a document viewing page, such as an article template, is generally named "article_ ID. htm".

4. Other templates:

The general templates included in the system are: homepage template, search template, RSS, JS compilation function template, etc. In addition, users can customize a template to create an arbitrary file.

11. How many labels are used in dede?

 Summary of PHP Professional Interview Questions (Theory)

Labels such as list content can only be used within their own scope, list labels can only be used in lists, and content labels can only be used in content labels.

Global tags can be used in all pages

12. Be familiar with common class libraries

(e.g. dedesql. class. php); Familiar with system function library (common. func. php); Be familiar with user-defined function library (extend. func. php); Be familiar with the foreground entry file (common. inc. php)

7、 WeChat public platform development

1. WeChat operation mechanism

 Summary of PHP Professional Interview Questions (Theory)

What language is used for communication between the public account and php: Xml

How to receive public 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:

(1) Text message;

(2) Image;

(3) Voice

(4) Video

(5) Geographical location;

(6) Link message;

(7) Event push

Type. Master the data transmission format when sending different message types

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

File_get_contents();

4. Common functions

The function to parse xml data into objects is

simplexml_load_string( )

The function to convert a string to an array is ___ explode_________, and the function to convert an array to a string is ____ implode___

The string encoding the URL string is ____ urlencode_ ______

5. Function of Sprintf()

When constructing various types of data into strings, the powerful function of sprintf rarely disappoints you. 〔〕 Because the usage of sprintf is almost the same as that of printf, except that the printing destination is different. The former is printed to the string, and the latter is directly output on the command line. This also leads to the fact that sprintf is much more useful than printf.

 Summary of PHP Professional Interview Questions (Theory)

This is all available in the manual.

6. Why can't the WeChat public account provide services?

1. Network reason and data interface reason

2. Code error, how to guess the reason

Check where the code is modified. If the code is correct

You can output data for a look. Using php to operate files

 $myfile = fopen("newfile.txt", "w"); $txt ="aaaaaaaaaa"; fwrite($myfile, $txt); fclose($myfile);

7. Event push of user-defined menu

single click

Click the jump link

Scan code push event

Scan code, push and pop up

Pop up the event that the system takes photos and sends pictures

Pop up the event of WeChat photo album sender

Events that pop up the geographic 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 an API interface (such as menu operation), you need to pass two values, appid and secure, to obtain the authorization code of the application

8、 Description of self mastered technology

1. Take PHP+MYSQL as the direction, master smart 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, master MYSQL, MSSQL and other databases; Familiar with PHP development under Linux

2. Front end technology: proficient in DIV+CSS web layout, javascript, JQuery framework, AJAX technology, photoshop image processing

3. One year of project development experience, developed 'XXXXXXXX' using smart, developed 'XXXXXXXX' using ThinkPHP, developed the public account of 'Employment Service Network' using WeChat public platform, developed enterprise stations using dream weaving system, etc

 Watson Blog
  • This article is written by Published on October 15, 2017 00:15:28
  • This article is collected and sorted by the website of Mutual Benefit, and the email address for problem feedback is: wosnnet@foxmail.com , please keep the link of this article for reprinting: https://wosn.net/678.html

Comment