search
HomeBackend DevelopmentPHP TutorialSummary of the latest classic PHP interview questions (Part 2)

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.

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
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么查找字符串是第几位php怎么查找字符串是第几位Apr 22, 2022 pm 06:48 PM

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment