简体   繁体   English

PHP:mysqli与mysql套接字的持久连接?

[英]PHP: mysqli persistent connection with mysql socket?

for persistent connection 用于持久连接
this is said to the rule.. 据说这是规则。
appending " p: " 附加“ p:

$co = new mysqli('p:localhost', 'user', 'pass', 'db');

but what if you want to use.. 但是如果您想使用该怎么办..

$co = new mysqli(NULL, 'user', 'pass', 'db', NULL, '/run/mysqld/mysqld.sock');

where do you place the 你在哪里放置

 p:  ?

Based on mysqli construct docs : 基于mysqli构建文档

it should work like this: 它应该像这样工作:

$co = new mysqli('p:localhost', 'user', 'pass', 'db', NULL, '/run/mysqld/mysqld.sock');`

as NULL is evaluated to localhost anyway. 因为无论如何都会将NULL评估为localhost。

host 主办

Can be either a host name or an IP address. 可以是主机名或IP地址。 Passing the NULL value or the string "localhost" to this parameter, the local host is assumed. 将NULL值或字符串“ localhost”传递给此参数,将假定为本地主机。 When possible, pipes will be used instead of the TCP/IP protocol. 如果可能,将使用管道代替TCP / IP协议。

Prepending host by p: opens a persistent connection. 通过p前置主机:打开一个持久连接。 mysqli_change_user() is automatically called on connections opened from the connection pool. 在从连接池打开的连接上会自动调用mysqli_change_user()。

socket 插座

Specifies the socket or named pipe that should be used. 指定应使用的套接字或命名管道。

Note: Specifying the socket parameter will not explicitly determine the type of connection to be used when connecting to the MySQL server. 注意:指定套接字参数不会显式确定连接到MySQL服务器时要使用的连接类型。 How the connection is made to the MySQL database is determined by the host parameter. 与MySQL数据库的连接方式由host参数决定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM