• Register
0 votes
186 views

Problem :

I am getting following error in my error log file

[18-Nov-2019 19:09:55 UTC] PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1040] Too many connections' in /home/root/products/db.php:2

Stack trace: /home/root/products/db.php(2): PDO->__construct('mysql:host=loca...', 'database', 'password')

/home/root/products/by-brand.php(2): include_once('/home/root/...')

{main} thrown in /home/root/products/db.php on line 2

[18-Nov-2019 19:15:11 UTC] PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1286 Unknown storage engine InnoDB in /home/root/products/detail.php:8

Stack trace: /home/root/products/name.php(8): PDO->prepare('select * from p...')

{main} thrown in /home/root/products/name.php on line 8

I have tried to solve this issue by closing every script by using $db=null; but it is not working for me.

I also contacted the service provider.

Why am I getting this error?

My db.php file has following code. Can you tell if this is fine?

My db.php as follows:

$db = new PDO('mysql:host=localhost;dbname=mobiles;charset=utf8', 'root', '**somePassword**');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
6 5 3
6,930 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

This issue is happening due to the limit of database's configuration.If you have the permissions to edit the configuration file of your database service then you can update the max_connections value.

You can also try to run following SQL query (Please Note : take care about this value.)

SET GLOBAL max_connections = 512;

and following is to get current value of all variables:

SHOW GLOBAL VARIABLES LIKE '%max_connections%'

By doing this please try to set PDO object to null when you don't need it. This will help in closing the connection to your database and PHP need not wait for script to finish and after that close active connections.

Further Readings: 

http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html

9 7 4
38,600 points

Related questions

0 votes
1 answer 29 views
29 views
Problem: If I open my error log file then sometimes I see the below error: PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1040] Too many connections' in /home/root/products/db.php:2 Stack trace: /home/root/products/ ... 'root', '**somePassword**'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
asked Aug 8, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 53 views
53 views
Problem : Facing migration error on Laravel 5.4 with php artisan make:auth command as follows: syntax error or access violation: 1071 specified key was too long; max key length is 767 bytes
asked Nov 13, 2019 peterlaw 6.9k points
0 votes
1 answer 30 views
30 views
Problem : I am beginner to PHP. I want to store my data in my MySQL database so I have written below code my code works perfectly but want to add the check if a email already exists in my database then I want to redirect to the another page. My Code as shown below : <?php if(empty( ... ."','".$_POST['time']."')"; if (!mysql_query($sql)) { die('Fatal Error: ' . mysql_error()); } mysql_close(); } ?>
asked Feb 28, 2020 mphil 2.3k points
0 votes
1 answer 37 views
0 votes
1 answer 174 views
174 views
Problem: I want to add some of the data to my database but I am receiving below error: Catchable fatal error: Object of class PDOStatement could not be converted to string in /var/www/mandje.php on line 114. This is the code which is causing above error: foreach($_SESSION ... ->execute($sql); I am unable to find out my mistake. Looking for a PHP expert who can guide me in fixing the above error.
asked Aug 21, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 10 views
10 views
My small project is about making an entry of a recipe. So it includes some special characters. So when I made an entry and save them to the database, it generates an error. But when I tried to insert it to my PHPAdmin, everything works well. Here is my recipe ... ½ tablespoons water 6 cups chicken broth 2 ¼ tablespoons soy sauce 1 tablespoon fish sauce"; Anyone who can show me how to save this?
asked Oct 28, 2020 RJ Lam 650 points
0 votes
1 answer 13 views
13 views
I have three tables that are link to each other via id of the main entry. For example, I need to create a user entry with username, name and password in the user table. And then after this information is created into the database, I need to create two new information to handle its ... label> <input type="text" name="name" id="name"><br><br> <button id="submit" name="submit">Submit</button> </form>
asked Oct 28, 2020 RJ Lam 650 points
0 votes
1 answer 15 views
15 views
Hello, I have a small project that requires me to create a dynamic form using jquery and php. This project has two sections. The Left side is the entry of at least two fields: <input type="text" name="first_name"> <input type="text" name="last_name"> Is it possible also to add and delte ... <tr> <td>1</td> <td>Abc</td> <td>Xyz</td> </tr> </table> I would be thankful in advance for helping me.
asked Oct 27, 2020 RJ Lam 650 points
0 votes
1 answer 11 views
11 views
I need to update my database but it seems not working. I posted my code here. I don&rsquo;t know what&rsquo;s wrong with this code. Can somebody help me? The record already exists in my database with the id of 1. But when I execute this code, and make an entry, then click the update ... "> </td> </tr> </table> <input name="save" type="submit" id="update" value="Update"> </form> </body> </html>
asked Oct 20, 2020 azriel 590 points
0 votes
1 answer 19 views
19 views
I need to copy a table information from one database to another table of another database. Is it possible for me to do it? if it is, can someone help me? Thank you!
asked Oct 12, 2020 robin_gallo 420 points