|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-11-26 13:13 UTC] hhsnakeg at gmail dot com
Description: ------------ When I use persist connection on PHP use call mysqli_real_connect with parameter host 'p:localhost' causes error connection when I call the connection second time. After that, a new database connection is created with a new id. When we connect to the database for the first time we see a message in the general log: 454 Connect dbuser@localhost on dbscheme using Socket When we reuse connection (connect second time) we see a message in the general log: 454 Connect Access denied for user 'dbuser'@'localhost' (using password: NO) 455 Connect dbuser@localhost on dbscheme using Socket and in the error log we see the same message: 454 [Note] Access denied for user 'dbuser'@'localhost' (using password: NO) I think this error appeared after changes in version 7.2.24 (Fixed bug #76809 (SSL settings aren't respected when persistent connections are used). Test script: --------------- <?php function connect() { $connectionID = mysqli_init(); $ok = mysqli_real_connect($connectionID, 'p:localhost', 'dbuser', 'dbpass', 'dbscheme', 3306, "", 0); mysqli_select_db($connectionID, 'dbsheme'); } connect(); connect(); PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 20:00:01 2025 UTC |
I think you have something going on with the your function. you need to sense if it exists, and the connection scheme is installed (if you are looking for deployment) Try: a fixed version of the Procedure style in a function (which I would not recommend): function connect(){ if(!isset($connectionID)){ $connectionID = mysqli_init(); if (!$connectionID){die("mysqli_init failed");} mysqli_real_connect($connectionID,'localhost', 'dbuser', 'dbpass', 'dbscheme'); }} connect(); But you shouldn't use a connect in a function ever! You should always control the connection state, and close the connection at the end of page.... use "require" call then mysqli_close($con); at the end of working with the database, in your php page. But If you need to call a connection, within a page, I recommend checking it first: if(!isset($connectionID)){ $connectionID = mysqli_init(); $con= mysqli_real_connect($connectionID,'localhost', 'dbuser', 'dbpass', 'dbscheme'); } Here is an object oriented version: $mysqli = mysqli_init(); if (!$mysqli) {die("mysqli_init failed");} $con -> real_connect("localhost","dbuser","dbpass","my_db"); Just remember to use the procedural: mysqli_close($con); or the object oriented: $mysqli -> close(); to close the connection at the bottom of your php page.