Home >Backend Development >PHP Tutorial >Summary of the latest classic PHP interview questions (Part 2)

Summary of the latest classic PHP interview questions (Part 2)

黄舟
黄舟Original
2017-03-18 09:17:34978browse

Summary of PHP junior classic interview questions (Part 1)

17. The difference between isset, empty, and is_null

isset determines whether the variable is defined or empty

  变量存在返回ture,否则返回false
  变量定义不赋值返回false
  unset一个变量,返回false
  变量赋值为null,返回false

Empty: Determine whether the value of the variable is empty. Anything that can be converted to false is empty. If it is empty, it returns true, otherwise it returns false.

    "",0,"0",NULL,FALSE都认为为空,返回true
    没有任何属性的对象都认为是空

is_null: Check whether the incoming value (value, variable, expression) is null

    定义了,但是赋值为Null
    定义了,但是没有赋值
    unset一个变量

18, front-end debugging tool

  • Firefox firebug

  • Chrome development tools

  • Emmet

  • JSON format verification tool

19. Briefly describe the differences between index, primary key, unique index and joint index in mysql, and what impact they have on the performance of the database ( From both reading and writing) (Sina Technology Department)

Indexes are a special file (the indexes on the InnoDB data table are an integral part of the table space). They contain all records in the data table. reference pointer.
The only task of a normal index (an index defined by the keyword KEY or INDEX) is to speed up access to data.
Normal indexes allow indexed data columns to contain duplicate values. If you can determine that a certain data column will only contain values ​​that are different from each other, you should use the keyword UNIQUE to define it as a unique index when creating an index for this data column. In other words, a unique index can ensure the uniqueness of data records.
The primary key is a special unique index. Only one primary key index can be defined in a table. The primary key is used to uniquely identify a record and is created using the keyword PRIMARY KEY.
The index can cover multiple data columns, such as the INDEX (columnA, columnB) index, which is a joint index.
Indexes can greatly improve the speed of data query, but will reduce the speed of inserting, deleting, and updating tables, because when performing these write operations, the index file must be operated.

20. What is a transaction in a database?

A transaction is an ordered set of database operations as a unit. A transaction is considered successful if all operations in the group succeed, even if only one operation fails, the transaction is not successful. If all operations are completed, the transaction is committed and its modifications are applied to all other database processes. If an operation fails, the transaction is rolled back and the effects of all operations in the transaction are canceled. The four major characteristics of ACID are atomicity, isolation, consistency, and durability.

21. Do you understand XSS attacks? How to prevent it?

XSS is a cross-site scripting attack. First, the cross-site scripting vulnerability is used to execute a script constructed by the attacker in a privileged mode, and then the unsafe Activex control is used to perform malicious behaviors.
Use the htmlspecialchars() function to filter the submitted content to materialize the special symbols in the string.

22.What causes SQL injection vulnerability? How to prevent it?

Cause of SQL injection: During the program development process, you did not pay attention to standard writing of sql statements and filtering of special characters, which resulted in the client being able to submit some sql statements normally through global variables POST and GET. implement.

Ways to prevent SQL injection:
  1. Turn on magic_quotes_gpc and magic_quotes_runtime settings in the configuration file

  2. Used when executing sql statements addslashes Convert sql statements

  3. Try not to omit double quotes and single quotes when writing Sql statements.

  4. Filter out some keywords in the sql statement: update, insert, delete, select, *.

  5. Improve your naming skills of database tables and fields, name some important fields according to the characteristics of the program, and choose names that are difficult to guess.

  6. Set register_globals to off in the Php configuration file, turn off global variable registration

  7. ControlError message, do not browse Output error information on the server and write the error information to the log file.

23.What are the main attack methods on PHP websites?

  1. Command Injection

  2. eval Injection

  3. Client Script Insertion

  4. Cross Site Scripting (XSS)

  5. SQL injection attack(SQL injection)

  6. Cross Site Request Forgery Attack
    Forgeries, CSRF

  7. Session Hijacking

  8. Session Fixation

  9. HTTP Response Splitting

  10. File upload Vulnerability(File Upload Attack)

  11. Directory Traversal(Directory Traversal)

  12. Remote File Inclusion Attack(Remote Inclusion)

  13. Dynamic Variable
    Evaluation

  14. URL attack

  15. Form Submit spoofed attack (Spoofed Form
    Submissions)

  16. HTTP request spoofed attack (Spoofed HTTP Requests)

24. What are single entry and multiple entries in the framework? What are the advantages and disadvantages of single entry?

  1. Multiple mouths complete user requests by accessing different files. A single entry only web program directs all requests to a script file.

  2. A single entrance makes it easier to control permissions and facilitate security checks on http requests.
    Disadvantages: The URL does not look so beautiful, especially not friendly to search engines.

25. For relational database, indexing is a very important concept. Please answer a few questions about indexing:

a ), what is the purpose of indexing?
  1. Quickly access specific information in the data table and improve retrieval speed

  2. Create a unique index to ensure the uniqueness of each row of data in the database table sex.

  3. Accelerate joins between tables

  4. When using grouping and sorting clauses for data retrieval, you can significantly reduce grouping in queries and sorting time

b) What is the negative impact of indexes on the database system?

Negative impact:
Creating and maintaining indexes takes time, and this time increases as the amount of data increases; indexes need to occupy physical space, not only tables need to occupy data Space, each index also needs to occupy physical space; when the table is added, deleted, modified, the index must be dynamically maintained, which reduces the data maintenance speed.

c) What are the principles for creating indexes for data tables?
  1. Create an index on the most frequently used fields to narrow the query range.

  2. Create indexes on frequently used fields that need to be sorted

d). Under what circumstances is it inappropriate to create an index?
  1. It is not appropriate to create indexes for columns that are rarely involved in queries or columns with many duplicate values.

  2. For some special data types, it is not suitable to create indexes, such as text fields (text), etc.

26. Briefly describe the difference between MyISAM and InnoDB in MySQL database

The most important feature that distinguishes it from other databases is its plug-in type table storage engine. Remember: the storage engine is based on tables, not databases.

The difference between InnoDB and MyISAM:

InnoDB storage engine: Mainly for OLTP (Online Transaction Processing, online transaction processing) applications, it is the first complete support ACID transaction storage engine (BDB's first storage engine to support transactions, has stopped development).

Features:

  • Row lock design, support foreign keys;

  • Support similar to Oracle Style consistent non-locking read (ie: read operations will not generate locks by default);

  • InnoDB places the data in a logical table space and is performed by InnoDB itself manage. Starting from the MySQL 4.1 version, each InnoDB storage engine table can be stored in an independent ibd file;

  • InnoDB uses MVCC (Multi-version Concurrency Control: read cannot will block writing, and writing will not block reading) to obtain high concurrency, and implements the 4 isolation levels of the SQL standard (the default is REPEATABLE level);

  • InnoDB also provides High-performance and high-availability functions such as insert buffer, double write, adaptive hash index, and read ahead;

  • InnoDB uses a clustered method to store data in the table. Each object is stored in the order of the primary key (if the primary key is not explicitly specified when creating the table, InnoDB will generate a 6 for each row. byte ROWID, and use this as the primary key);

  • The InnoDB table will have three hidden fields: In addition to the 6-byte DB_ROW_ID mentioned above, there is also a 6-byte DB_TX_ID (Transaction ID) and 7-byte DB_ROLL_PTR (pointing to the address of the corresponding rollback segment). This can be seen through innodb monitor;

##MyISAM storage engine: is the storage engine officially provided by MySQL, mainly for OLAP (Online Analytical Processing, online analysis and processing) applications.
Features:

  • Does not support transactions, but supports table locations and full-text indexes. The operation speed is fast;

  • MyISAM storage engine table consists of MYD and MYI, MYD is used to store data files, and MYI is used to store index files. The MySQL database only caches its index files, and the caching of data files is left to the operating system itself;

    Starting from MySQL 5.0 version, MyISAM supports 256T of single table data by default;

27. Explain the differences between MySQL outer joins, inner joins and self-joins

First of all, what is cross join: Cross join Also called Cartesian product, it refers to directly matching all records in one table with all records in another table without using any conditions.

Inner join is a cross-connection with only conditions. Records that meet the conditions are filtered out according to a certain condition. Records that do not meet the conditions will not appear in the result set, that is, inner joins only connect Matching lines.
Outer join The result set not only contains rows that meet the join conditions, but also includes all data rows
in the left table, right table, or two tables. These three situations are called They are left outer join, right outer join, and full outer join.

Left outer join, also called left join, the left table is the main table, all records in the left table will appear in the result set, for those records that do not match in the right table, they still need to be displayed, on the right The corresponding field values ​​are filled with NULL. Right outer join, also called right join, the right table is the main table, and all records in the right table will appear in the result set. Left joins and right joins are interchangeable, and MySQL currently does not support full outer joins.

28. Write the names of more than three MySQL database storage engines (tip: not case sensitive)

MyISAM, InnoDB, BDB (BerkeleyDB), Merge, Memory (Heap), Example , Federated,
Archive, CSV, Blackhole, MaxDB and more than a dozen engines

29. What isObject-oriented? What are the main features? What are the major principles?

Object-oriented is a design pattern of a program, which helps improve the reusability of the program and makes the program structure clearer. The main features are: encapsulation, inheritance, and polymorphism.
FiveBasic principles: Single responsibility principle; Open and closed principle; Replacement principle; Dependency principle; Interface separation principle.

30. What is staticrouting and what are its characteristics? What is dynamic routing and what are its characteristics?

Reference answer:
Static routes are routes specified by routing tables designed and constructed by system administrators. It is suitable for networks where the number of gateways is limited and the network topology does not change frequently. Its disadvantage is that it cannot dynamically adapt to changes in network conditions. When network conditions change, the routing table must be modified by the network administrator.
Dynamic routing is dynamically constructed by routing protocols. Routing protocols update the contents of routing tables in real time by exchanging routing information they own. Dynamic routing can automatically learn the topology of the network and update the routing table. The disadvantage is that routing broadcast update information will occupy a large amount of network bandwidth.

31. Have you ever used Memcache cache? If so, can you briefly describe its working principle?

Memcahce stores all data in the memory, using a hash table. Each piece of data is composed of key and value. Each key is unique. When you want to access a certain value, first follow the steps to find it. value and return the result.
Memcahce uses the LRU algorithm to gradually clear out expired data.

32. List the popular Ajax frameworks? Explain what is the implementation principle of Ajax and what role does json play in Ajax?

Popular Ajax frameworks include jQuery, Prototype, Dojo, and MooTools.

The working principle of Ajax is that the specified location of one page can load all the output content of another page. In this way, a static page can also obtain the returned data information from the database. Therefore, Ajax technology enables a static web page to communicate with the server without refreshing the entire page, reducing user waiting time, thereby reducing network traffic and enhancing the friendliness of the customer experience.
When using Ajax, it involves data transmission, that is, returning data from the server to the client. The server and client use different script languages ​​to process data, which requires a common data format, XML and json are the two most commonly used, and json is simpler than XML.

33. Overview of the transaction rollback mechanism in Myql

A transaction is a sequence of database operations defined by the user. These operations are either done or not done at all. It is an indivisible unit of work. Transaction rollback refers to undoing the update operations to the database that have been completed by the transaction.

When you want to modify two different tables in the database at the same time, if they are not a transaction, when the first table is modified, an exception may occur during the modification process of the second table and it cannot be modified. At this time, only the second table can be modified. The two tables are still in their unmodified state, while the first table has been modified. And when you set them as a transaction, when the first table is modified and the second table is modified abnormally and cannot be modified, the first table and the second table will return to the unmodified state. This is called transaction rollback.

The above is the detailed content of Summary of the latest classic PHP interview questions (Part 2). 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