mysqli_connect

(PHP 5, PHP 7)

mysqli_connect别名 mysqli::__construct()

说明

此函数是该函数的别名: mysqli::__construct()

User Contributed Notes

php dot net dot comments at siteaboutnothing dot com 12-Jul-2017 07:28
By default port 3306 will be used.

To use a different port, enter it as another argument, not as part of the hostname:

mysqli_connect($db_host,$db_user,$db_pass,$db_database,$db_port);
zubkov dot rabota at gmail dot com 28-Jun-2017 05:16
To set a permanent connection use prefix 'p:'
example:

"$pMysqli = new mysqli('p:'.DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);"
thamizh82 at gmail dot com 20-Jan-2017 11:31
$con=mysqli_connect("localhost","my_user","my_password","my_db");

var_dump($con);  -> Return mysql object.

$conn = mysqli_connect(NULL, $user, $pass);
$conn = mysqli_connect('NULL', $user, $pass);
Return Same object given before. Not thrown false or error.

$conn = mysqli_connect('NULLTest', $user, $pass);
Return false
tuxedobob 17-Oct-2016 10:52
When using this function rather than the OO syntax, this function will return FALSE on error, rather than an object.
d4v3m0nk 03-Oct-2016 06:56
Worthwhile noting that the MySQLi library can still open a permanent connection, but a different command isn't used. Simply prepend "p:" to the MySQL hostname or address.

Using classes:
$this->mysqli = new mysqli('p:'. mysql_host, mysql_user, mysql_password, mysql_database);

Using command:
$link = mysqli_connect('p:mysql_host', 'mysql_user', 'mysql_password', 'mysql_database');