Home  >  Article  >  Backend Development  >  2017php classic interview questions

2017php classic interview questions

不言
不言Original
2018-04-21 10:32:071511browse

The content introduced in this article is about the 2017php classic interview questions, which has a certain reference value. Now I share it with you. Friends in need can refer to it

1. One of the major aspects of PHP language The advantage is cross-platform. What is cross-platform? 1. PHP basics:


The optimal combination of PHP’s operating environment is Apache MySQL PHP. This operating environment can be used in different It is configured on the operating system (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

The 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, but the value passed by post is not visible in the url

4. The value passed by Get is generally within 2KB, and the value passed by post can be Set it in php.ini

5. Get security is not low, post security is higher, but the execution efficiency is higher than Post

Suggestion:

1. The get type is less secure than the Post type. It contains confidential information. It is recommended to use the Post data submission type;

2 , it is recommended to use the Get method for data query; it is recommended to use the Post method for adding, modifying or deleting data;

The get method used by Baidu, because it can be seen from its URL

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

Framework: There are many frameworks, such as zendframe, CI, Yii, etc. What we have learned is thinkphp

template engine: there are many, some are in the textbooks, what we have learned is smarty

system: there are There are many, such as: Kangsheng's products (uchome, supesite, discuzX, etc.), Empire System, DEDE (Dream Weaver), ecshop, etc. What we have learned is DEDECMS, Ecshop

4 , tell me what web front-end technologies you have mastered?

Proficient in p 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 the JQuery framework to achieve partial refresh, reduce the pressure on the server, and improve the user experience

6. Security is crucial to a program. Please tell us what security mechanisms should be paid attention to during development?

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

7. How to improve the operating efficiency of the program during program development?

① Optimize SQL statements, try not to use select * in query statements, use which field to check which field; use less subqueries and can be replaced by table connections; use less fuzzy queries; ② Data table Create indexes in the program; ③ Generate cache for data frequently used in the program;

8. Can PHP be used with other databases?

PHP is the best combination with MYSQL database. Of course, PHP can also be used with other databases, such as MSSQL. PHP has reserved functions for operating MSSQL. Just turn it on. Use

9. Nowadays, 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 respectively. 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 and avoid code redundancy; ②M and V realize code separation, so that the same program can use different expressions

10. For json data format understand?

JSON (JavaScript Object Notation) is a lightweight data exchange format. The json data format is fixed and can be used for data transmission in multiple languages.

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

Json_encode: Convert PHP variables into json format

11. What are the differences 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, if you only output echo will be faster, and print_r is usually used to print information about variables, usually 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 in the server, cookie is stored in the browser

②Security: session security is higher than cookie

③session is a 'session service'. When using it, you need to enable the service. Cookies do not need to be enabled. You can directly use

14. PHP to process arrays Commonly used functions? (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() pushes one or more Elements are inserted at the end of the array (pushed 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( ) delete duplicate values ​​in the array; ⑧in_array() checks whether the specified value exists in the array;

15. What are the common functions for PHP to process strings? (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 Replace with another 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 a string; ⑧strrchr() finds the last occurrence of a string in another string; ⑨strstr() finds the first occurrence of a string in another string (case-sensitive sensitive); strrev() reverses 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() is used to intercept Chinese and English functions

16. Commonly used functions in PHP to process 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.

17. What are the common functions used in 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

18. What are the common functions for operating files in PHP? (Focus on the ‘parameters’ and ‘return value’ of the function)

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

19. 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 Wait, this item is very important. At work, it is often used 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

Back to top

2. Database part

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 are the integrity constraints?

Answer: Data Integrity refers to the accuracy and reliability of data.

is divided into the following four categories:

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

2) Domain integrity: It 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 the data between the tables and preventing data corruption. Missing or meaningless data proliferates in the database.

4) User-defined integrity: Different relational database systems often require some special constraints based 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 applications.

Transaction characteristics:

(1) Atomicity: that is, indivisibility, transactions are either all executed or none at all. .

(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) Persistence. 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 be If it fails, future operations will be rolled back to the state before the operation, or there will be 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: A 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 constraint on the uniqueness of records, requiring records to have unique identities, that is, the uniqueness of entities; Third normal form: 3NF is a constraint on field redundancy, that is, any field cannot be derived from other fields, it requires 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 angles; (3) Views provide a certain degree of logic for the database Independence; (4) Views can 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--unique Identifies a record, there cannot be duplicates, and it is not allowed to be empty

Foreign key--the foreign key of a table is the primary key of another table, the foreign key can be repeated, and it can be empty Value

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

##Function:

Primary key--used to ensure data integrity

External Key - used to establish connections with other tables

Index - 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 Field only accepts values ​​in a specific range?

Answer: Check restriction, which is defined in the database table to limit the value entered in the 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 be problematic in some cases. Lower impact on performance.

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

(1) In the Where clause: The connection between 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) Replace IN with EXISTS and NOT IN with NOT EXISTS.

(3) Avoid using calculations on index columns

(4) Avoid using IS NULL and IS NOT NULL# on index columns

## (5) To optimize the query, try to avoid full table scans. First, consider creating indexes on the columns involved in where and order by.

(6) Try to avoid null value judgment 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 expression operations on fields in the where clause, which will cause the engine to give up using the index and perform a full table scan

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

Answer: Subquery: A query nested in other queries is called a query.

The subquery is also called the inner query, and the statement containing the subquery is called the outer query (also called the main query).

All subqueries can be divided into two categories, namely correlated subqueries and non-correlated subqueries

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

(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, while varchar is a variable-length type. The difference between them is:

In a data column of type char(M), each value occupies M bytes. If a 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 will not Deadlock occurs; suitable for small data and small concurrency

innodb is a storage engine that supports transactions; suitable for applications with many insert and update operations; if designed properly, row locks (the biggest difference Just at the lock level); 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, and fast to read. Some functions do not support (transactions, etc.), table-level locks.

InnoDB: Supports features such as transactions, foreign keys, 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 of the publishing system. The increment of more than 50,000 items per day 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 and reduce the amount of data in a single table to improve query speed.

e. Add caching mechanisms, such as memcached, apc, etc.

f. For pages that do not change frequently, static pages are generated.

g. Write efficient SQL. For example, SELECT * FROM TABEL is changed to SELECT field_1, field_2, field_3 FROM TABLE.

21. For a website 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.

Back to top

3. Object-oriented part

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, fully 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;

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 distinguishes between uppercase and lowercase letters, while HTML does not.

(2) In HTML, you can omit the

or if the context clearly shows where the paragraph or list key ends. The end tag of the class. 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 to ensure that software components have The basis of 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, you can do it on the basis of an existing class. The content defined by the class is regarded as its own content, and some new content can be added, or the original method can be modified 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 refers to the specific type pointed to by the reference variable defined in the program and the method emitted through the reference variable The call is not determined during programming, but is determined during the running of the program. That is, which class instance object a reference variable will point to. The method call issued by the reference variable must be implemented in which class. It can be decided while the program is running.

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 of these things. and commonalities, and will ignore those aspects that are irrelevant to the current topic and goal, and focus on 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 that uses interface declaration.

(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) There can be constructors in abstract classes, but there are no constructors in interfaces.

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

(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, that is, overriding the methods of the parent class, that is, using the methods in the subclass to replace the methods inherited from the parent class, is also called method rewriting.

The key to overriding parent class methods is to create the same method in the parent class in the subclass, including the method's 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 for redundancy. Contains existing magic methods.

#__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 properties 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() is 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() is 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 of the current class 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 the class.

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 inside a class or outside a class, the access to 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: Call class constants

Call static methods

13, __autoload() method How does it work?

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 continues to execute. 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.

Back to top

##4. ThinkPHP part

1. Common PHP frameworks

Answer: thinkPHP

yii

ZendFramework

CakePhp

sy

2. How to understand TP Single entry file in?

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)

Define related constants for 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 The controller is responsible for scheduling control.

View (V): It consists 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 two storage engines MyISAM and InnoDB. Each engine has advantages and disadvantages.

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, then 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, so reading Of course it will be very fast. 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 Driven

TP official abbreviation 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): Behavior plays a decisive role in the architecture of the new version of ThinkPHP. On the core of the system, many label extension bits are set, and each label position can be sequentially perform their own independent actions. 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 (Driver): database driver, cache driver, tag library driver and template engine driver, as well as external class extensions.

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: Conventional 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 (located in Conf\convention under the system directory). .php), common parameters are configured by default according to most uses. 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.

The conventional configuration file will be automatically loaded by the system and does 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 the database. 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 numeric data types; (This has been mandatory since version 3.1 Field type verification has been performed)

(4) Use automatic verification and auto-complete mechanisms to perform custom filtering for applications;

(5) ) Use field type checking, automatic validation and automatic completion mechanisms to avoid malicious data entry.

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

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

//Enable debug mode

define('APP_DEBUG', true);

//Load the framework entry file

require './ThinkPHP/ThinkPHP.php';

After completing the development phase and deploying to the production environment , just delete the debug mode definition code to switch to deployment mode. After turning on debugging mode, the system will first load the system default debugging configuration file, and then load the project's debugging configuration file. The advantages of debugging mode are:

Turn on logging, 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, and data table field modifications will not be affected by the cache;

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

can be conveniently used at different stages of the development process, including development, testing, demonstration, etc. If necessary, separate 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 sequence of the configuration file, because the subsequent configuration will Overwrites the previous configuration with the same name (without taking effect), so the priority 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:

only need to be called in Action The following method:

$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 there is a custom model class, it will be instantiated automatically. Define the model class. If it does not exist, 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).

Back to top

##5. smarty template engine

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 smarty The compilation is actually the process of mixing php and html

## Smarty’s cache needs to be turned on manually. Smarty’s cache is to compile the After the file is executed, a static html page is generated 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 an application that uses The PHPtemplate engine

written in PHP aims to separate the PHP program from the artist

, so that the programmer can change the logical content of the program without affecting the page design of the artist. The program logic of the program will not be affected when the page is re-modified, which is particularly important in multi-person cooperation projects. (It is also easy to develop multi-style programs)Smarty advantages

1. Fast speed: 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.

Places where smarty is not suitable

1. Content that needs to be updated in real time. For example, like stock display, it requires frequent data updates 2. Small projects. Small projects where the artist and programmer are both on the same person because the project is simple

3. Use {$smarty} in templates to retain variables

{$smarty.get.page } //Similar to accessing $_GET[page]

{smarty.cookies.}

{smarty.post.} in a php script

{smarty.session.}

{smarty.server.}

4. Access variables in php in the template

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

{$smarty.const._MY_CONST_VAL}

{$smarty.const.__FILE__}

5. Variables Moderator

##{$var|modifier1|modifier2|...}

<{$str}>

<{$str| capitalize}><{*First letter in capital letters*}>

<{$str|upper}><{*All in capital letters*}> ;

<{$str|lower}><{*all lowercase*}>

<{$str|lower|upper}><{*All caps, adjusted from left to right*}>

##<{ $leg|truncate}><{*String interception, default 80 characters*}>

##<{$leg|truncate:10}> ;<{*String interception, the first 10, including...three characters*}>

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 browser parsing)

3. Encoding settings when connecting to the database

4. Use the header function in PHP files Determine the encoding

7. Caching mechanism

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

8. Smarty 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 from HTML, artists and programmers should perform their respective duties without interfering with each other.

#10. What are the main configurations of smarty?

1. Introduce smarty.class.php;

2. Instantiate the smarty object;

3. Re-modify the default template path;

4. Re-modify 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,

In other words, smarty technology separates the user UI from the PHP code.

In this way, programmers and artists can 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;

Use assign assignment and display display page in the 2.php page;

3. PHP code snippets are not allowed in smarty template files. All comments, variables, and functions must be included in delimiters.

A.{}

B. foreach

C. if else

D. include

E. Literal

Back to top

6. Secondary development system (DEDE, ecshop):

1. Understanding of secondary development

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

2. MVC

## Model data processing.

View template display.

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 one 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 the 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 the execution is completed, the controller layer decides which view layer the result will be assigned to.

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

Based on the error, modify the server configuration parameters and Baidu

##4. Function, template replacement, function addition and modification

In fact, it is the use of object-oriented applications, and the replacement of templates is similar to the use of smarty

##5. What secondary development have been used? thing?

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 or secondary development like PHP?

# Generally, small and medium-sized enterprises use CMS systems 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. What is the understanding of custom models 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 models that come with the system, we can use it to build different types of sites. For example, you can use an atlas to build a picture site, and use software models 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., and customize these models Only then can you build a site with more content.

It is equivalent to us automatically adding the table structure to adapt to changes in current needs

10. In dede concepts, when 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, Individual pages or custom tags individually defined by users can also choose 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 using "list_identification ID.htm ” Naming.

3. Archive template:

represents the template of the document viewing page, such as article template, generally use "article_identification ID.htm" name.

4. Other templates:

Generally, the templates included in the system include: 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?

# Tags such as #list content 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 on all pages

##12. Familiar with common class libraries

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

Back to top

7. WeChat public platform development

1.

WeChat operating mechanism

What language is used to communicate between the official 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 types

##WeChat currently provides 7 basic message types, which are:

(1) Text message (text);

(2) Picture message (image);

(3) Voice ( voice)

(4) Video (video)

(5) Location;

(6) Link message (link);

(7) Event push (event)

type. Master the data transfer format when sending different message types

4. Function that reads the entire file into a string Yes

File_get_contents

5. Commonly used functions

The function that parses xml data into objects is

simplexml_load_string( )

The function to convert a string to an array is ___ explode_________, the function that converts an array into a string is ____implode________.

The string that encodes the URL string is ____urlencode________ .

6. The role of Sprintf function

You can check the manual for this.

7. Reasons why the WeChat public account cannot provide services ?

1. Network reason, data interface reason

2. Code error, how to guess the reason

Check where you modified it. 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 );

##8. Custom menu event push

Click on the link

## Click on the jump link

## Scan the QR code to push the event

Scan Code push and pop up

Events that pop up the geographical location selector

##9. The role of token

Security mechanism verification , used for security verification between WeChat server and PHP server10. The role of Appid and secrect


Request api interface (such as menu operation) You need to pass two values ​​​​appid and secrect to obtain the application authorization code

Return to top

##8. Description of the technologies you have mastered:

1. Taking PHP MYSQL as the direction, proficient in smarty template engine, ThinkPHP framework, WeChat Public platform development, DEDE, ecshop and other secondary development systems, have a certain understanding of object-oriented; database, proficient in MYSQL, MSSQL and other databases; familiar with PHP development under Linux

2. Front-end technology: Proficient in p CSS web page layout, javascript, JQuery framework, AJAX technology, photoshop image processing

3. One year of project development experience, used smarty to develop 'XXXXXXXX', ThinkPHP to develop 'XXXXXXXX', used WeChat public platform to develop the public account of 'Employment Service Network', and used Dream Weaver System to develop Pass the enterprise website, etc.

Related recommendations:

2017 Latest PHP Classic Interview Questions Summary

Summary of PHP Interview Questions

The above is the detailed content of 2017php classic interview questions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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