php-mysql扩展的mysql_connect/mysql_pconnect比较
author: selfimpr
blog: http://blog.csdn.net/lgg201
mail: lgg860911@yahoo.com.cn
item
mysql_connect
mysql_pconnect
函数原型
resource mysql_connect($host_port, $user, $passwd, $newlink, $client_flags);
第四个参数$newlink标记是否创建新的资源对象
resource mysql_pconnect($host_port, $user, $passwd, $client_flags);
allow_persistent指令
设置此指令使得两个函数行为均和mysql_connect()一致
连接资源对象获取
对$host_port, $user, $passwd, $client_flags求哈希值
在普通资源列表(EG(regular_list))中查找连接对象(已找到并且没有设置$newlink强制创建新连接)
检查找到的对象是否资源类型
从查找到的对象中读取连接对象
将当前获取的连接对象设置为全局默认连接对象
增加连接对象的引用计数, 设置zval属性返回
对$host_port, $user, $passwd, $client_flags求哈希值
从持久化资源列表(EG(persist_list))中查找连接对象(没有找到)
检查max_links配置指令限制是否到达
检查max_persistent配置指令限制是否到达
分配连接对象(php_mysql_conn)空间
设置连接对象的基础属性
初始化驱动层连接对象(mysqlnd/libmysql两种方式)
设置连接超时时间
发起驱动层的真实连接请求
构造持久化列表元素对象, 将新连接对象设置到元素中
将连接对象更新到持久化列表中
更新(增加)num_persistent/num_links计数
注册资源类型返回值
将当前获取的连接设置为全局默认连接对象
对$host_port, $user, $passwd, $client_flags求哈希值
在普通资源列表(EG(regular_list))中查找连接对象(未找到或设置了$newlink强制创建新连接)
检查max_links配置指令限制
分配连接对象(php_mysql_conn)空间
设置连接对象基础属性
初始化驱动层连接对象(mysqlnd/libmysql)
设置连接超时时间
发起驱动层的真实连接
将连接对象注册为资源类型返回值
将连接对象更新到普通资源列表(EG(regualr_list))中
更新num_links计数
将当前获取的连接对象设置为全局默认连接对象
对$host_port, $user, $passwd, $client_flags求哈希值
从持久化资源列表中查找连接对象(已找到)
检查查找到的持久化资源的类型是否匹配
从持久化资源中读取连接对象
设置连接对象基本属性
检查服务端是否主动关闭
如果服务端主动关闭则进行重连
注册资源类型返回值
将当前获取的连接设置为全局默认连接对象
regular_list Vs. persistent_list
regular_list和persistent_list两者都是HashTable
两者都是执行全局环境executor_globals的成员
两者生命周期不同, regular_list在php_request_shutdown()时被释放, 也就是单个请求处理完成之后释放, 而persistent_list在php_module_shutdown()的时候调用zend_shutdown()释放, 也就是在整个进程完成执行时释放

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

AI Hentai Generator
Generate AI Hentai for free.

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

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.
