PHP database operation code collection
Note: The closed connection must be displayed when using this connection 2. mysql_pconnect()-Establish a database connection Format: resource mysql_pconnect([string hostname [:port] [:/path/to/socket] [, string username] [, string password]]) example:
Note: Using this connection function does not require closing the connection explicitly. It is equivalent to using a connection pool 3. mysql_close()-Close the database connection example:
4. mysql_select_db()-Select database Format: boolean mysql_select_db(string db_name [, resource link_id]) example:
5. mysql_query()-Query MySQL Format: resource mysql_query (string query, [resource link_id]) example:
Note: If SQL query If the execution is successful, the resource identifier is returned, and if it fails, FALSE is returned. If the update is executed successfully, it returns TRUE, otherwise it returns FALSE 6. mysql_db_query()-Query MySQL Format: resource mysql_db_query(string database, string query [, resource link_id]) example:
Note: In order to make the code clear, it is not recommended to use this function call 7. mysql_result()-obtain and display data Format: mixed mysql_result (resource result_set, int row [, mixed field]) example:
Description: The simplest and least efficient data acquisition function 8. mysql_fetch_row()-Get and display data Format: array mysql_fetch_row (resource result_set) example:
Description: The function gets the entire data row from result_set and puts the values in an indexed array. Usually the list() function is used 9. mysql_fetch_array()-Get and display data Format: array mysql_fetch_array (resource result_set [, int result_type]) example:
Another example:
Instructions: The values of result_type are: MYSQL_ASSOC: The field name represents the key, and the field content is the value MYSQL_NUM: Numeric index array, the operation is the same as the mysql_fetch_ros() function MYSQL_BOTH: Returned both as an associative array and as a numerical index array. The default value of result_type. 10. mysql_fetch_assoc()-Get and display data Format: array mysql_fetch_assoc (resource result_set) Equivalent to calling mysql_fetch_array(resource, MYSQL_ASSOC); 11. mysql_fetch_object()-Get and display data Format: object mysql_fetch_object(resource result_set) example:
Description: Returns an object, which is the same as mysql_fetch_array() in operation 12. mysql_num_rows()-the number of selected records Format: int mysql_num_rows(resource result_set) example:
Description: Only useful when determining the number of records obtained by select query. 13. mysql_affected_rows() - the number of records affected by Insert, update, delete Format: int mysql_affected_rows([resource link_id]) example:
Description: This function gets the number of rows affected by the INSERT, UPDATE or DELETE update statement 14. mysql_list_dbs()-Get database list information Format: resource mysql_list_dbs([resource link_id]) example:
Description: Display all database names 15. mysql_db_name()-Get the database name Format: string mysql_db_name(resource result_set, integer index) Description: This function obtains the database name located at the specified index in the result_set returned by mysql_list_dbs() 16. mysql_list_tables()-Get the list of database tables Format: resource mysql_list_tables(string database [, resource link_id]) example:
Description: This function gets the table names of all tables in the database 17. mysql_tablename()-Get the name of a database table Format: string mysql_tablename(resource result_set, integer index) example:
Description: This function gets the table name located at the specified index in the result_set returned by mysql_list_tables() 18. mysql_fetch_field()-Get field information Format: object mysql_fetch_field(resource result [, int field_offset]) example:
Instructions: The returned object has a total of 12 object properties: name: field name table: the table where the field is located max_length: the maximum length of the field not_null: 1 if the field cannot be null, otherwise 0 primary_key: 1 if the field is the primary key, 0 otherwise unique_key: 1 if the field is a unique key, 0 otherwise multiple_key: 1 if the field is non-unique, 0 otherwise numeric: 1 if the field is numeric, 0 otherwise blob: 1 if the field is a BLOB, 0 otherwise type: the data type of the field unsigned: 1 if the field is an unsigned number, 0 otherwise zerofill: 1 if the field is "zero filled", 0 otherwise 19. mysql_num_fields()-Get the number of fields in the query Format: integer mysql_num_fields(resource result_set) example:
20. mysql_list_fields()-Get the field names of all fields in the specified table Format: resource mysql_list_fields (string database_name, string table_name [, resource link_id]) example:
21, mysql_field_flags()-Get the specified field options Format: string mysql_field_flags (resource result_set, integer field_offset) example:
22 , mysql_field_len()-Get the maximum length of the specified field Format: integer mysql_field_len (resource result_set, integer field_offset) example:
illustrate: If mysql_field_len($reseult, 0) = 16777215 Then numer_format(mysql_field_len($result)) is equal to 16,777,215 23. mysql_field_name()-get the field name Format: string mysql_field_name (resource result_set, int field_offset) example:
24, mysql_field_type()-get the field type Format: string mysql_field_type (resource result_set, int field_offset) example:
25, mysql_field_table()-Get the table name where the field is located Format: string mysql_field_table (resource result_set, int field_offset) example:
|

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
