2

I have recently started using Laravel and absolutely love it, however I keep coming across the error:

SQLSTATE[42000] [1203] User 'root' already has more than 'max_user_connections' active connections

I know there is a way to change the MySQL variable to allow more connections, however this isn't an option with my host and along with this, there is no way I should of hit this limit.

Some example queries are:

return User::where('users.username', '=', Auth::user()->username)->join('settings', 'settings.username', '=', 'users.username')->first();
return Char::orderBy('calculate', 'ASC')->groupBy('charid')->get();

So my question is, what should I be looking for in order to combat the error? Should I be disconnecting myself from the database at the end of each function? Or something completely different?

Any help would be appreciated in this matter.

roadkill247
  • 213
  • 1
  • 5
  • 12

2 Answers2

0

No, Once Change the username root to following username like *system a*nd try it

0

What version of Laravel do you have? Go to "application/config.database.php" or "app/config/database.php". From here you can add custom options to your laravel database settings.

The "database.php" contains at the end something like this:

    'connections' => array(


    'mysql' => array(
        'driver'   => 'mysql',
        'host'     => 'localhost',
        'database' => 'db_name',
        'username' => 'db_username',
        'password' => 'username_password',
        'charset'  => 'utf8',
        'prefix'   => '',
    ),

),

You can add "options" to that array, just like this:

    'connections' => array(


    'mysql' => array(
        'driver'   => 'mysql',
        'host'     => 'localhost',
        'database' => 'db_name',
        'username' => 'db_username',
        'password' => 'username_password',
        'charset'  => 'utf8',
        'prefix'   => '',
        'options'  => array(
                            //here you will add your custom options
                      ),
    ),

),
Pascut
  • 3,291
  • 6
  • 36
  • 64
  • 1
    I've added the following: 'options' => array( PDO::ATTR_PERSISTENT => true, PDO::ATTR_TIMEOUT => 20, ), but still have the issue – roadkill247 Apr 08 '14 at 11:36
  • 2
    try: 'options' => array( PDO::ATTR_TIMEOUT => 0, ), for unlimited time. If it still don't work, the problem is your computer/host, in this case you'll find the answer here: http://stackoverflow.com/a/4079589/1564840 – Pascut Apr 09 '14 at 07:39