Rajan
Rajan

Reputation: 2425

Check number of connections to MySQL in codeigniter

Is it possible to check the number of connections to a mysql server in codeigniter?

I Have two CI Applications which I access each other's database. However, I get the following error:

A Database Error Occurred

Unable to connect to your database server using the provided settings.

Filename: core/Loader.php

Line Number: 347

When I opened my logs I saw a warning which said Too Many Connections.

So I want to debug why I am getting this error.

Upvotes: 1

Views: 875

Answers (1)

Rejoanul Alam
Rejoanul Alam

Reputation: 5398

There are mysql query to see opened connection. You may run following query to see all corresponding variables and their value

In CI3

$ww = $this->db->query('show status like "%conn%"');
$t = $ww->result_array();
var_dump($t);

here Threads_connected variable is number of connection currently opened in MySQL. You may extract it as

echo $t['13']['Value'];

Upvotes: 2

Related Questions