• Register
0 votes
145 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

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 10 views
10 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 Raphael Pacheco 4.9k points
0 votes
1 answer 41 views
41 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 26 views
26 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 mphil 2.3k points
0 votes
1 answer 29 views
0 votes
1 answer 5 views
5 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 1 day ago azriel 360 points