Summary of the latest PHP classic interview questions (part II)

Source: Internet
Author: User
An index is a special file (an index on an InnoDB data table is an integral part of a tablespace) that contains reference pointers to all records in the data table. Summary of PHP Elementary classic interview questions (part 1)

17. differences between isset, empty, and is_null

Isset determines whether the variable is defined or empty

If a variable exists, true is returned. otherwise, false is returned. if the definition of a variable is not assigned a value, false is returned. if the value of false is null, false is returned.

Empty: determines whether the variable value is null. if it can be converted to false, all values are null. if it is null, true is returned. otherwise, false is returned.

"", 0, "0", NULL, FALSE are considered NULL, and true is returned. all objects without any attribute are considered NULL.

Is_null: checks whether the input value (value, variable, expression) is null.

Defined, but the value is Null, but no value is assigned to unset a variable.
18. front-end debugging tools
  • Firebug of Firefox

  • Chrome development tools

  • Emmet

  • JSON format verification tool

19. briefly describe the differences between indexes, primary keys, unique indexes, and joint indexes in mysql and the impact on database performance (from the read and write aspects) (xinlang Technology Department)

An index is a special file (an index on an InnoDB data table is an integral part of a tablespace) that contains reference pointers to all records in the data table.
The only task of a common INDEX (INDEX defined by the KEY or INDEX keyword) is to speed up data access.
Normal indexes allow indexed data columns to contain duplicate values. If you can determine that a data column will only contain different values, you should use the keyword UNIQUE to define it as a UNIQUE index when creating an index for this data column. That is to say, the unique index can ensure the uniqueness of data records.
A primary key is a special unique index. only one primary key index can be defined in a table. a primary key is used to uniquely identify a record and is created using the KEY word primary key.
Indexes can overwrite multiple data columns, such as INDEX (columnA, columnB) indexes. this is the union INDEX.
Indexes can greatly improve the data query speed, but reduce the speed of inserting, deleting, and updating tables, because the index files must be operated during these write operations.

20. what is the transaction in the database?

A transaction is a group of sequential database operations as a unit. If all operations in the group are successful, the transaction is considered successful. even if only one operation fails, the transaction fails. If all operations are completed, the transaction is committed, and the modifications are applied to all other database processes. If an operation fails, the transaction will be rolled back and all operations affected by the transaction will be canceled. ACID is characterized by atomicity, isolation, consistency, and durability.

21. do you know about XSS attacks? How to prevent it?

XSS is a cross-site scripting attack. first, XSS uses the cross-site scripting vulnerability to execute scripts constructed by attackers in a privileged mode, and then uses insecure Activex controls to execute malicious behaviors.
Use the htmlspecialchars () function to filter submitted content so that the special symbols in the string are materialized.

22. Why does the SQL injection vulnerability occur? How to prevent it?

Cause of SQL injection: During program development, you do not pay attention to writing SQL statements and filtering special characters. as a result, the client can submit some SQL statements through the global variable POST and GET for normal execution.

Prevent SQL injection:
  1. Enable magic_quotes_gpc and magic_quotes_runtime settings in the configuration file

  2. Use addslashes to convert SQL statements when executing SQL statements

  3. Do not omit double quotation marks or single quotation marks when writing SQL statements.

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

  5. Improve the naming skills of database tables and fields, and name some important fields according to the characteristics of the program, which is not easy to guess.

  6. Set register_globals to off in the Php configuration file and disable global variable registration.

  7. Control Error Information. do not output error information in the browser and write the error information to the log file.

23. What are the main attack methods for PHP websites?
  1. Command Injection)

  2. Eval Injection)

  3. Script Insertion)

  4. Cross-Site Scripting (XSS)

  5. SQL injection attacks)

  6. Cross-Site Request Forgery
    Forgeries, CSRF)

  7. Session Hijacking)

  8. Session Fixation)

  9. HTTP Response Splitting attack (HTTP Response Splitting)

  10. File Upload Attack)

  11. Directory Traversal vulnerability (Directory Traversal)

  12. Remote File Inclusion attack)

  13. Dynamic function injection (Dynamic Variable)
    Evaluation)

  14. URL attack)

  15. Spoofed Form
    Submissions)

  16. HTTP request spoofing (Spoofed HTTP Requests)

24. What are the advantages and disadvantages of a single portal and multiple portals in the framework?
  1. Multiple interfaces are used to access different files to complete user requests. A single portal only directs all requests of the web program to a script file.

  2. A single portal makes it easier to control permissions and allows you to perform security checks on http requests.
    Disadvantage: The URL looks less beautiful, especially unfriendly to search engines.

25. for relational databases, indexing is a very important concept. please answer a few questions about indexing: a) What is the purpose of indexing?
  1. Quick access to specific information in a data table to improve retrieval speed

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

  3. Accelerate the connection between tables

  4. When you use grouping and sorting clauses to retrieve data, you can significantly reduce the time for grouping and sorting in queries.

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

Negative impact:
It takes time to create and maintain indexes. this time increases with the increase of data volume. indexes require physical space, not only for tables, but for each index; when adding, deleting, modifying, and modifying tables, indexes must also be dynamically maintained, which reduces the data maintenance speed.

C) What are the principles for creating an index for a data table?
  1. Create an index on the most frequently used field to narrow the query range.

  2. Create an index on frequently used and sorted fields

D) under what circumstances should indexes not be created?
  1. Indexes are not suitable for columns that are rarely involved in queries or columns with a large number of repeated values.

  2. For some special data types, indexes are not suitable, such as text fields.

26. differences between MyISAM and InnoDB in MySQL databases

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

Differences between InnoDB and MyISAM:

InnoDB storage engine:Mainly for OLTP (Online Transaction Processing, Online Transaction Processing) applications, is the first storage engine that fully supports ACID transactions (BDB's first storage engine that supports transactions, development is stopped ).

Features:

  • Row lock design and support for foreign keys;

  • Supports Oracle-like consistent non-locked read (that is, by default, read operations do not produce locks );

  • InnoDB stores data in a logical tablespace and is managed by InnoDB itself. From MySQL, you can save the form of each InnoDB storage engine to an independent ibd file;

  • InnoDB achieves high concurrency by using MVCC (multi-Version Concurrency control: read does not block write, write does not block read, in addition, four isolation levels (REPEATABLE by default) of the SQL standard are implemented );

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

  • InnoDB uses clustered to store the data in the table. the storage of each subject is stored in the primary key order (if the primary key is specified when the table is created explicitly, innoDB generates a 6-byte ROWID for each row and uses it as the primary key );

  • The InnoDB table has three hidden fields: apart from the six-byte DB_ROW_ID mentioned above, there are also six bytes of DB_TX_ID (transaction ID) and the 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 a storage engine officially provided by MySQL. it is mainly used for OLAP (Online Analytical Processing, Online Analytical Processing) applications.
Features:

  • Transactions and full-text indexes are not supported. Fast operation speed;

  • MyISAM storage engine tables are composed of MYD and MYI. MYD is used to store data files and MYI is used to store index files. MySQL databases only cache their index files, and the data files are cached by the operating system;
    Starting from MySQL, MyISAM supports TB of single table data by default;

27. explain the differences between MySQL external and internal connections and self-connections

First, let's talk about cross-join:Cross join is also called Cartesian product. it means that all records in one table are directly matched with all records in another table without any conditions.

Internal connectionOnly cross-join with conditions is used. records that meet the conditions are filtered out based on a condition. records that do not meet the conditions are not displayed in the result set, that is, the inner join only connects matching rows.
External connectionThe result set contains not only rows that meet the connection conditions, but also the left table, right table, or two tables.
The three data rows are called left outer join, right outer join, and full outer join.

The left outer join, also known as the left join. the left table is the master table. all records in the left table will appear in the result set. the records that do not match in the right table will still be displayed, the field values corresponding to the right are filled with NULL. Right outer join, also known as Right Join. the right table is the master table, and all records in the right table appear in the result set. The left and right connections are interchangeable. MySQL does not support all external connections currently.

28. write the names of more than three MySQL database storage engines (note: case insensitive)

MyISAM, InnoDB, BDB (BerkeleyDB), Merge, Memory (Heap), Example, Federated,
Dozens of engines, such as Archive, CSV, Blackhole, and MaxDB

29. what is object-oriented? What are the main features? What are the principles?

Object-oriented is a design pattern of programs, which improves the reusability of programs and makes program organizations clearer. The main features are encapsulation, inheritance, and polymorphism.
Five basic principles: single responsibility principle, open and closed principle, replacement principle, dependency principle, and interface separation principle.

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

Reference answer:
Static routing is defined in the route table designed and constructed by the system administrator. Suitable for networks with limited number of gateways and the network topology structure does not change frequently. The disadvantage is that the network condition cannot be dynamically applied. when the network condition changes, the network administrator must modify the route table.
Dynamic Routing is dynamically built by the routing selection protocol. routing protocols exchange their own routing information to update the content of the route table in real time. Dynamic Routing automatically learns the topology of the network and updates the route table. The disadvantage is that the route Broadcast Update information occupies a large amount of network bandwidth.

31. have you used Memcache cache? if you have used it, can you briefly describe how it works?

Memcahce stores all data in the memory and uses a hash table. each piece of data is composed of key and value, and each key is unique, when you want to access a value, first find the value and then return the result.
Memcahce uses the LRU algorithm to gradually clear expired data.

32. list popular Ajax frameworks? Describe how Ajax is implemented and what role does json play in Ajax?

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

The working principle of Ajax is that all the output content of another page can be loaded at a specified position of a page, so that a static page can also obtain the returned data information in the database. Therefore, Ajax technology enables a static webpage to communicate with the server without refreshing the entire page, reducing user waiting time and network traffic, enhances the user experience.
When Ajax is used, it involves data transmission, that is, the data is returned from the server to the client, and the server and client use different footsteps languages to process the data, respectively, this requires a common data format. XML and json are the most commonly used data formats, while json is simpler than XML.

33. Overview of the transaction rollback mechanism in Myql

A transaction is a sequence of user-defined database operations. these operations are either fully performed or not performed, and are an inseparable unit of work, transaction rollback is to cancel the database update operations completed by the transaction.

When we 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 of the second table, but they cannot be modified, at this time, only the second table is in the status before modification, and the first table has been modified. When you set them as a transaction, when the first table is modified, the second table fails to be modified due to an exception, both the first and second tables must return to the unmodified state, which is called transaction rollback.

The above is the details of the latest PHP classic interview questions (next). For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.