开发者

Do multiple mysqli_queries use the same connection?

开发者 https://www.devze.com 2022-12-22 05:46 出处:网络
I have a mysqli_query statement like so: $result = mysqli_query($connection,$query) 开发者_Python百科

I have a mysqli_query statement like so:

$result = mysqli_query($connection,$query) 
开发者_Python百科

I am wondering: If I call mysqli_query multiple times during the execution of a script, does it use the same connection to the db? Or is a new connection established each time?

Thanks,


It should use the same connection, providing you don't tell it to reconnect.


mysql_query() (which is different from mysqli_query() but should behave the same in this regard) always uses the last opened connection if one isn't provided.

So for this:

$connection1 = mysqli_connect('host1');
$query1 = mysqli_query('SELECT column1');
$query2 = mysqli_query('SELECT column2');

$connection2 = mysqli_connect('host2');
$query3 = mysqli_query('SELECT column3');

$query and $query2 will both run on the connection to host1, and $query3 will run on the connection to host2

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号