0

How do I execute a command as and when a new mysql connection is established from php?

$con=mysqli_connect("localhost","root","","gts");

In the above exmaple, I need to pass set sql command :

sql_log_bin = 0

This will make sure that the commands executed by this connection will not be written to binary log. I have another "normal" connection that will work as usual and write all the commands to binary log.

In other words I need 2 connections to mysql one with disabled binary logging. I should be able to decide which one to use. How is it done in PHP?

4

2 回答 2

2

首先创建两个连接。

$con1=mysqli_connect("localhost","root","","gts");
$con2=mysqli_connect("localhost","root","","gts");

然后在其中一个上禁用您的二进制日志

mysqli_query($con1, "SET sql_log_bin = 0");
于 2013-07-08T13:38:43.993 回答
1

As you need two connections with different parameters, just establish two connections:

$con1 = mysqli_connect("localhost","root","","gts");
$con2 = mysqli_connect("localhost","root","","gts");

Then have a look at mysqli_options function:

bool mysqli_options ( mysqli $link , int $option , mixed $value );

In your case, it'll be something like

mysqli_options ( $con1 , MYSQLI_INIT_COMMAND , "SET sql_log_bin = 0" );

to turn this binary log off on connection 1.

Finally, when you need to run any queries, use $con1 if you do not need binary logging and $con2 if you do.

于 2013-07-08T13:41:24.147 回答