简体   繁体   中英

PHP: mysqli persistent connection with mysql socket?

for persistent connection
this is said to the rule..
appending " 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 :

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.

host

Can be either a host name or an IP address. Passing the NULL value or the string "localhost" to this parameter, the local host is assumed. When possible, pipes will be used instead of the TCP/IP protocol.

Prepending host by p: opens a persistent connection. mysqli_change_user() is automatically called on connections opened from the connection pool.

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. How the connection is made to the MySQL database is determined by the host parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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