Reputation: 97
we have an application which has at most 50K Users active at peak hours, for this we are using SQLServer as its backend DB, now we are planning to migrate it to MySQL.So as part of this, we need to check if MySQL can handle the traffic. so far I have tried mysql_pconnect() and when I check the active connections in MYSQL console it is not reflecting the expected number as this function reuses the connections.It would be very helpful if someone can tell me a way to open multiple connections to DB.
Upvotes: 0
Views: 41
Reputation:
Try to make multiple calls to mysql_connect(),
Check this example:
$dbh1 = mysqli_connect($hostname, $username, $password);
$dbh2 = mysqli_connect($hostname, $username, $password, true);
mysqli_select_db('database1', $dbh1);
mysqli_select_db('database2', $dbh2);
Now query database 1 pass the first link identifier:
mysqli_query('select * from tablename', $dbh1);
and for database 2 pass the second:
mysqli_query('select * from tablename', $dbh2);
Upvotes: 0
Reputation: 830
Use this to create 2 different connections:
$first_db_conn = new mysqli('localhost', 'user_1', 'pw_1', 'db_1');
$second_db_conn = new mysqli('localhost', 'user_2', 'pw_2', 'db_2');
you can then:
$first_db_conn->query("SELECT * FROM `users` LIMIT 1");
$second_db_conn->query("SELECT * FROM `users` LIMIT 1");
Upvotes: 1