• Register
0 votes
223 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 59 views
59 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 5 views
5 views
Problem: As I mentioned in my previous query, I'm having difficulties with my learning; I've tried searching the web but haven't been able to find adequate information; could you assist me in continuing my project?
asked Apr 1 rakib1 51.5k points
0 votes
1 answer 58 views
58 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
1 vote
1 answer 2 views
2 views
Problem : I create an object of class Topic, $topic = new Topic(); $results = $topic->getAllTopics(); When run it ,there is always an error like this : Fatal error: Call to a member function query() on null in /Applications/XAMPP/xamppfiles/htdocs/forumproject/libraries/Topic.php on line 25 i.e. $this->db->query(...) Someone, Please help me to resolve this issue.?
asked Mar 27 Shovo210 13.3k points
0 votes
1 answer 3 views
3 views
Problem: The code throws a lot of errors such as : Deprecated: mysql_connect(): The MySQL extension is deprecated and will be removed in the future: use MySQL or PDO instead in C:\wamp\www\btn\index.PHP on line 2 and:- mysqli_fetch_array() error on line 109. What is the problem with the given code? Is there anyone who can help me with this?
asked Mar 22 ummesalma 24.5k points
0 votes
1 answer 4 views
4 views
Problem: it outputs the error: Syntax error or access violation: 1064 No idea how to fix this. any ideas?
asked Mar 22 ummesalma 24.5k points
0 votes
1 answer 2 views
2 views
Problem: How I can resolve the following issue. Too many connections from this ip filezilla.
asked Mar 23 PkGuy 13.1k points
1 vote
1 answer 3 views
3 views
Problem : Why I receive this error: Fatal error: Call to a member function execute() on boolean in C:...\rent.php on line 18 Any ideas on what I need to do to fix this? Thanks!
asked Mar 27 Shovo210 13.3k points
0 votes
1 answer 494 views
494 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