php extension MySQLi
The mysqli extension allows us to access the functionality provided by MySQL 4.1 and above.
mysqli extension and persistent connections
The persistent connection of the mysqli extension was introduced in PHP5.3. Support already exists in PDO MYSQL and ext/mysql. The idea behind persistent connections is that the connection between the client process and the database can be maintained and reused through a client process, rather than being created and destroyed multiple times. This reduces the overhead of needing to create a new connection each time, and unused connections are cached and ready for reuse.
Unlike the mysql extension, mysqli does not provide a special method for opening a persistent connection. When you need to open a persistent connection, you must add p: before the host name when connecting.
The problem with using persistent connections is that they can be in an unpredictable state on the client side. For example, a table lock might be activated before the client terminates unexpectedly. A new client process that reuses the persistent connection will get the connection "as is". In this way, a new client process needs to do any possible cleanup work in order to better use persistent connections, which increases the burden on the programmer.
The persistent connection of the mysqli extension provides built-in cleanup processing code. The cleanup work done by mysqli includes:
Rolling back active transactions
Close and delete temporary tables
Unlock tables,
Reset session variables
Close prepared statements (often happens in PHP)
Close processing The program
releases the lock acquired via GET_LOCK()
This ensures that the persistent connection returned from the connection pool is in a clean state before the client process uses it.
The mysqli extension completes this cleanup work by automatically calling the C-API function mysql_change_user().
The feature of automatic cleaning has advantages and disadvantages. The advantage is that programmers no longer need to worry about additional cleanup code because they are called automatically. However, the disadvantage is that the code may be potentially slower because the cleanup code needs to be executed every time a connection is returned from the connection pool.
This automatic cleaning code can be turned off by defining MYSQLI_NO_CHANGE_USER_ON_PCONNECT when compiling php.
The mysqli extension supports persistent connections when using Mysql Native Driver or Mysql Client Library (libmysql).
MySQLi class
represents a connection between PHP and Mysql database.
mysqli::$affected_rows — Gets the number of affected rows in a previous MySQL operation
mysqli::autocommit — Turn on or off the automatic command commit transaction mode of this database connection
mysqli::begin_transaction — Starts a transaction
mysqli::change_user — Changes the user of the specified database connection
mysqli::character_set_name — Returns the default character encoding of the current database connection
mysqli::$client_info — Get MySQL client info
mysqli::$client_version — Returns the MySQL client version as a string
mysqli::close — Close a previously opened database connection
mysqli::commit — Commit a transaction
mysqli::$connect_errno — Returns the error code from last connect call
mysqli: :$connect_error — Returns a string description of the last connect error
mysqli::__construct — Open a new connection to the MySQL server
mysqli::debug — Performs debugging operations
mysqli::dump_debug_info — Output debugging information to Log
mysqli::errno — Returns the error code of the most recent function call
mysqli::$error_list — Returns a list of errors from the last command executed
mysqli::$error — Returns a string description of the last error
mysqli::$field_count — Returns the number of columns for the most recent query
mysqli::get_charset — Returns a character set object
mysqli::get_client_info — Get MySQL client info
mysqli_get_client_stats — Returns client per-process statistics
mysqli_get_client_version — Returns the MySQL client version as an integer
mysqli::get_connection_stats — Returns statistics about the client connection
mysqli::$host_info — Returns a string representing the type of connection used
mysqli::$protocol_version — Returns the version of the MySQL protocol used
mysqli::$server_info — Returns the version of the MySQL server
mysqli::$server_version — Returns the version of the MySQL server as an integer
mysqli::get_warnings — Get result of SHOW WARNINGS
mysqli::$info — Retrieves information about the most recently executed query
mysqli::init — Initializes MySQLi and returns a resource for use with mysqli_real_connect()
mysqli::$insert_id — Returns the auto generated id used in the last query
mysqli::kill — Asks the server to kill a MySQL thread
mysqli::more_results — Check if there are any more query results from a multi query
mysqli::multi_query — Performs a query on the database
mysqli::next_result — Prepare next result from multi_query
mysqli::options — Set options
mysqli::ping — Pings a server connection, or tries to reconnect if the connection has gone down
mysqli::poll — Poll connections
mysqli::prepare — Prepare an SQL statement for execution
mysqli::query — 对数据库执行一次查询
mysqli::real_connect — Opens a connection to a mysql server
mysqli::real_escape_string — Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection
mysqli::real_query — 执行一个mysql查询
mysqli::reap_async_query — Get result from async query
mysqli::refresh — Refreshes
mysqli::release_savepoint — Rolls back a transaction to the named savepoint
mysqli::rollback — 回退当前事务
mysqli::rpl_query_type — Returns RPL query type
mysqli::savepoint — Set a named transaction savepoint
mysqli::select_db — 选择用于数据库查询的默认数据库
mysqli::send_query — 发送请求并返回结果
mysqli::set_charset — 设置默认字符编码
mysqli::set_local_infile_default — Unsets user defined handler for load local infile command
mysqli::set_local_infile_handler — Set callback function for LOAD DATA LOCAL INFILE command
mysqli::$sqlstate — Returns the SQLSTATE error from previous MySQL operation
mysqli::ssl_set — Used for establishing secure connections using SSL
mysqli::stat — Gets the current system status
mysqli::stmt_init — 初始化一条语句并返回一个用于mysqli_stmt_prepare(调用)的对象
mysqli::store_result — Transfers a result set from the last query
mysqli::$thread_id — Returns the thread ID for the current connection
mysqli::thread_safe — 返回是否是线程安全的
mysqli::use_result — Initiate a result set retrieval
mysqli::$warning_count — Returns the number of warnings from the last query for the given link
MySQLi_STMT类
代表一个prepared语句。
mysqli_stmt::$affected_rows — Returns the total number of rows changed, deleted, or inserted by the last executed statement
mysqli_stmt::attr_get — Used to get the current value of a statement attribute
mysqli_stmt::attr_set — Used to modify the behavior of a prepared statement
mysqli_stmt::bind_param — Binds variables to a prepared statement as parameters
mysqli_stmt::bind_result — Binds variables to a prepared statement for result storage
mysqli_stmt::close — Closes a prepared statement
mysqli_stmt::data_seek — Seeks to an arbitrary row in statement result set
mysqli_stmt::$errno — Returns the error code for the most recent statement call
mysqli_stmt::$error_list — Returns a list of errors from the last statement executed
mysqli_stmt::$error — Returns a string description for last statement error
mysqli_stmt::execute — Executes a prepared Query
mysqli_stmt::fetch — Fetch results from a prepared statement into the bound variables
mysqli_stmt::$field_count — Returns the number of field in the given statement
mysqli_stmt::free_result — Frees stored result memory for the given statement handle
mysqli_stmt::get_result — Gets a result set from a prepared statement
mysqli_stmt::get_warnings — Get result of SHOW WARNINGS
mysqli_stmt::$insert_id — Get the ID generated from the previous INSERT operation
mysqli_stmt::more_results — Check if there are more query results from a multiple query
mysqli_stmt::next_result — Reads the next result from a multiple query
mysqli_stmt::$num_rows — Return the number of rows in statements result set
mysqli_stmt::$param_count — Returns the number of parameter for the given statement
mysqli_stmt::prepare — Prepare an SQL statement for execution
mysqli_stmt::reset — Resets a prepared statement
mysqli_stmt::result_metadata — Returns result set metadata from a prepared statement
mysqli_stmt::send_long_data — Send data in blocks
mysqli_stmt::$sqlstate — Returns SQLSTATE error from previous statement operation
mysqli_stmt::store_result — Transfers a result set from a prepared statement
mysqli_result类
代表从一个数据库查询中获取的结果集
mysqli_result::$current_field — Get current field offset of a result pointer
mysqli_result::data_seek — Adjusts the result pointer to an arbitrary row in the result
mysqli_result::fetch_all — Fetches all result rows as an associative array, a numeric array, or both
mysqli_result::fetch_array — Fetch a result row as an associative, a numeric array, or both
mysqli_result::fetch_assoc — Fetch a result row as an associative array
mysqli_result::fetch_field_direct — Fetch meta-data for a single field
mysqli_result::fetch_field — Returns the next field in the result set
mysqli_result::fetch_fields — Returns an array of objects representing the fields in a result set
mysqli_result::fetch_object — Returns the current row of a result set as an object
mysqli_result::fetch_row — Get a result row as an enumerated array
mysqli_result::$field_count — Get the number of fields in a result
mysqli_result::field_seek — Set result pointer to a specified field offset
mysqli_result::free — Frees the memory associated with a result
mysqli_result::$lengths — Returns the lengths of the columns of the current row in the result set
mysqli_result::$num_rows — Gets the number of rows in a result
MySQLi_Driver类
MySQLi 驱动.
client_info
客户端API头版本(比如:(string)"5.1.49")
client_version
客户端版本(比如:(int)50149)
driver_version
Mysqli驱动版本(比如:(int)101009)
embedded
是否开启了MySQLi嵌入式支持。
reconnect
允许或阻止重连接(查看INI指令中的mysqli.reconnect)
report_mode
设置为MYSQLI_REPORT_OFF, MYSQLI_REPORT_ALL或者 MYSQLI_REPORT_STRICT (为错误抛出异常,译注:需要和MYSQLI_REPORT_ERROR联合使用), MYSQLI_REPORT_ERROR (报告MYSQL错误)和 MYSQLI_REPORT_INDEX (报告索引相关的错误)的任意组合。
mysqli_driver::embedded_server_end — Stop embedded server
mysqli_driver::embedded_server_start — Initialize and start embedded server
mysqli_driver::$report_mode — Enables or disables internal report functions
MySQLi_Warning类
代表一个Mysql警告。
message
消息字符串
sqlstate
SQL状态
errno
错误编号
mysqli_warning::__construct — The __construct purpose
mysqli_warning::next — The next purpose
mysqli_sql_exception类
mysqli异常处理类
mysqli_sql_exception extends RuntimeException { /* 属性 */ protected string $sqlstate ; /* 继承的属性 */ protected string $message ; protected int $code ; protected string $file ; protected int $line ; }
别名和过时的Mysqli 函数
mysqli_bind_param — mysqli_stmt_bind_param的别名
mysqli_bind_result — mysqli_stmt_bind_result的别名
mysqli_client_encoding — mysqli_character_set_name的别名
mysqli_connect — 别名 mysqli::__construct
mysqli::disable_reads_from_master — Disable reads from master
mysqli_disable_rpl_parse — 禁用RPL解析
mysqli_enable_reads_from_master — 开启从主机读取
mysqli_enable_rpl_parse — 开启RPL解析
mysqli_escape_string — 别名 mysqli_real_escape_string
mysqli_execute — mysqli_stmt_execute的别名
mysqli_fetch — mysqli_stmt_fetch的别名。
mysqli_get_cache_stats — 返回客户端Zval缓存统计信息
mysqli_get_metadata — mysqli_stmt_result_metadata的别名
mysqli_master_query — 在主/从机制中强制在主机中执行一个查询
mysqli_param_count — mysqli_stmt_param_count的别名
mysqli_report — 开启或禁用(Mysql)内部(错误)报告函数
mysqli_rpl_parse_enabled — 检查是否开启了RPL解析
mysqli_rpl_probe — RPL探测
mysqli_send_long_data — mysqli_stmt_send_long_data的别名
mysqli_set_opt — mysqli_options的别名
mysqli_slave_query — 在主/从机制中强制在从机上执行一个查询

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











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.
