开发者

Do multiple mysqli_queries use the same connection?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜